Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Given: Throwable is Exception's superclass. When I read tests on writing your own 'exceptions', I see examples of Throwable being used in the catch block and other text's show new Exception() being used in the catch block. I have yet to see an explanation of when one should use each. My question is this, When should Throwable be used and when should new Exception() be used? EDIT: Inside t...
Are there any guidelines on exception propagation in Java? When do you add an exception to the method signature? For example: if an exception is only thrown when an essential program resource is missing, and can only be handled at the top level, do I propagate it through all methods using this exception through all the methods using the erring method? Are there any good practices? Any bad pra...
Sometimes I see try { }catch(Throwable e) { } And sometimes try { }catch(Exception e) { } What is the difference
I'd like to use to a custom exception to have a user-friendly message come up when an exception of any sort takes place. What's a good straightforward way of doing this? Are there any extra precautions I should take to avoid interfering with Swing's EDT?
What is the best practice to follow when you need to throw an exception which was not defined in an interface that you are implementing? Here is an example: public interface Reader { public abstract void read() throws IOException; } public class CarrotReader implements Reader { public void read() throws IOException {} } public class CupcakeReader implements Reader { public void ...
I'm developing web-application with JSF. I tested it as I was able to but from time to time runtime exceptions are thrown. So, how to redirect user to special error page every time an exception is thrown (instead of displaying 500 Error with full tomcat logs)?
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 ?
Assuming that requestScope.importMe is expecting a path to a jsp file <c:choose> <c:when test="${!empty requestScope.importMe && fileExists(requestScope.importMe) }"> <c:import url="${requestScope.importMe}" /> ... How can I check if the file exists before trying to include it so that an error is not thrown? I'd like to avoid using inline Java. Somethi...
after searched for a while I still couldn't find any answer to my question, even there's couple of Generics related topic, so here you go: ArrayList<? super IOException> list = new ArrayList<Exception>(); list.add(new FileNotFoundException("this is ok.")); list.add(new IOException("This is ok")); list.add(new ClassCastException("compile err"));//why compile err? list.add(new Except...
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.
What type of exception is caught by the beanshell catch(ex): Exception or Throwable?. Example: try { .... } catch (ex) { }
Consider some code that can throw a checked exception (an exception of type Exception). Your code catches the exception, of course. You don't just swallow the exception either, your code reports it in some way to the user through your user interface. In a log file, perhaps, or using a GUI pop-up. Should the text you report to the user include the message text of the exception. That is, the te...
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(...
Is there any possibility of exceptions to occur other than RuntimeException in Java? Thanks.
I find that Java's reflection API is exception verbose, and I often want to catch each specific exception, but just throw Exception. Is this poor practice, or do you really throw all of those exceptions on the method signature? Every method that calls that method must then deal with each of those specific exceptions in some way. Instead, I'm thinking of doing this: public void someMethod() ...
As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?
hi can any one pls give me simple example for creating and using UserDefined Exceptions in java thanks in advance SS
I have a button that plays an audio file on its click listener. If the button is clicked again and again while the audio file is being played then the app crashes. What's the solution? Here is some code for reference: private OnClickListener btnMercyListener = new OnClickListener() { public void onClick(View v) { // Toast.makeText(getBa...
is exception a subclass of error?
Where/How could I get a list of all the java and javac's error and warning messages?
I would like to handle errors with (unchecked) exceptions. I heared that for each kind of exception I should create a subclass of either Error or RuntimeException. What's the difference?
 /*
  * Copyright 1994-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;

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

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

    
Constructs a new exception 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 Exception() {
        super();
    }

    
Constructs a new exception 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 Exception(String message) {
        super(message);
    }

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

Note that the detail message associated with cause is not automatically incorporated in this exception'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 Exception(String messageThrowable cause) {
        super(messagecause);
    }

    
Constructs a new exception 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 exceptions that are little more than wrappers for other throwables (for example, java.security.PrivilegedActionException).

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 Exception(Throwable cause) {
        super(cause);
    }
New to GrepCode? Check out our FAQ X