Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
What is considered the best, most comprehensive way to close nested streams in Java? For example, consider the setup: FileOutputStream fos = new FileOutputStream(...) BufferedOS bos = new BufferedOS(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); I understand the close operation needs to be insured (probably by using a finally clause). What I wonder about is, is it necessary to e...
I'm trying to learn more about basic Java and the different types of Throwables, can someone let me know the differences between Exceptions and Errors?
Documentation for java.lang.Error says: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch But as java.lang.Error is subclass of java.lang.Throwable I can catch this type of throwable. I understand why this is not good idea to catch this sort of exceptions. As far as I understand, if we decide to caught it, the catch ...
To the point: how would you handle a server-side HTTP 4nn/5nn errors in jQuery's ajax requests? This case concerns a JSP/Servlet webapplication at the server side. Here I am not talking about trivial runtime exceptions such as NullPointerException and so on. Assume that they're all handled perfectly. A good example of such a HTTP 4nn/5nn error is 401 unauthorized (insufficient user rights) and ...
Sometimes I see try { }catch(Throwable e) { } And sometimes try { }catch(Exception e) { } What is the difference
Is there any point catching an out of memory error (java.lang.OutOfMemoryError) in Java?
I'm a student and right now going through exceptions and errors in Java. I have a confusion about when error occurs. Please share with me some examples.
I was told that in Java, unchecked exceptions can be caught in a try block, but if it's caught, isn't it called a checked exception?
I want to ask why we don't have to add try-catch block to a RuntimeException while we should do that with other exceptions? I mean like : public class Main { public static void main(String[] args) { throw new RuntimeException(); } } Edit : when I say : throw new RuntimeException(); it is so clear that there is an exception will happen ,so why the compiler doesn't forbid that ?
I have to serialize around a million items and I get the following exception when I run my code: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Unknown Source) at java.lang.String.<init>(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at org.gi...
They are very different kind of languages and the way they handle exceptions might be rather different.. How is exception handling implemented and what are the implementation difference within these languages? I am asking this question also because I noticed that C++ exception handling seems to be very slow compared to the JavaScript version.
Hi this was the question me in the interview. What is the main difference between Unchecked exception and error as both are not caught.They will terminate the program. I was bit puzzled. Can anybody elaborate on this.
I have a thread in a Java web application that causes a java.lang.OutOfMemoryError: Java heap space exception, but the try/catch block does not catch the error. Sample code: private void doSomeWork() { try { processData(); //Causes OutOfMemoryError System.out.println("This line does not execute"); } catch (Exception e) { System.out.println(...
I am trying to understand the Java Error class. I have a good understanding of the Exception class, but can't find examples of code for the Error class. I've tried searching the web and also the java.sun website, but I'm not finding anything useful to help me understand this better.How to use Error class in programs and where we have to use that?
What type of exception is caught by the beanshell catch(ex): Exception or Throwable?. Example: try { .... } catch (ex) { }
I am trying to add a custom throws clause to a method definied by an interface. This is not possible. How could I bypass it? Here is some code: private void sendRequestToService(final ModuleRequest pushRequest) { ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { try ...
What is the best practice when dealing with Errors within a server application? In particular, how do you think an application should handle errors like OutOfMemoryError? I'm particularly interested in Java applications running within Tomcat, but I think that is a more general problem. The reason I'm asking is because I am reviewing a web application that frequently throws OOME, but usuall...
My project got like 20 unhandled exceptions, doesn't matter why, and I was wondering how do they affect the JVM? It doesn't crash, but I'm still wondering what are their footprint in JVM. Where do they go?
Is it a bad practice to catch the Throwable? For example something like this: 1. try { 2. // Some code 3. } catch(Throwable e) { 4. // handle the exception 5. } Is this a bad practice or we should be as specific as possible? Thanks!
I'm working on a cross platform application in Java which currently works nicely on Windows, Linux and MacOS X. I'm trying to work out a nice way to do detection (and handling) of 'crashes'. Is there an easy, cross-platform way to detect 'crashes' in Java and to do something in response? I guess by 'crashes' I mean uncaught exceptions. However the code does use some JNI so it'd be nice to be a...
As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?
  /*
   * Copyright 1995-2000 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.lang;

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.

Author(s):
Frank Yellin
Since:
JDK1.0
See also:
ThreadDeath
 
 public class Error extends Throwable {
     static final long serialVersionUID = 4980196508277280342L;

    
Constructs a new error with null as its detail message. The cause is not initialized, and may subsequently be initialized by a call to Throwable.initCause(java.lang.Throwable).
 
     public Error() {
         super();
     }

    
Constructs a new error with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to Throwable.initCause(java.lang.Throwable).

Parameters:
message the detail message. The detail message is saved for later retrieval by the Throwable.getMessage() method.
 
     public Error(String message) {
         super(message);
     }

    
Constructs a new error with the specified detail message and cause.

Note that the detail message associated with cause is not automatically incorporated in this error's detail message.

Parameters:
message the detail message (which is saved for later retrieval by the Throwable.getMessage() method).
cause the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.4
 
     public Error(String messageThrowable cause) {
         super(messagecause);
     }

    
Constructs a new error with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause). This constructor is useful for errors that are little more than wrappers for other throwables.

Parameters:
cause the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.4
 
    public Error(Throwable cause) {
        super(cause);
    }
New to GrepCode? Check out our FAQ X