java.lang.Object
java.lang.Throwable
- All Implemented Interfaces:
- Serializable
- Direct Known Subclasses:
- Error, Exception
- See Also:
- Top Examples, Source Code,
printStackTrace()
, getStackTrace()
, RuntimeException
, NamingException
, RemoteException
, PrinterIOException
, PrivilegedActionException
, WriteAbortedException
, InvocationTargetException
, UndeclaredThrowableException
, ClassNotFoundException
, ExceptionInInitializerError
, initCause(Throwable)
, IOException
, Collection
public Throwable fillInStackTrace()
- See Also:
printStackTrace()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Throwable getCause()
- See Also:
initCause(Throwable)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[10]Catch RuntimeException
By Anonymous on 2002/07/31 17:44:37 Rate
try {
someMethodThatThrowsAnException ( ) ;
} //end try
catch ( RuntimeException e ) {
System.out.println ( "In catch block" ) ;
System.out.println ( "Msg is:\n" + e.getMessage ( ) ) ;
System.out.println ( "Cause is:\n" + e.getCause ( ) ) ;
System.out.println ( ) ;
throw new Exception ( e ) ;
} //end catch
[257]Chained exceptions
By Anonymous on 2003/05/17 14:06:39 Rate
//Chained exceptions
try {
// Fails because prefix is too short
File f = File.createTempFile ( "x", "y" ) ;
} catch ( Exception e ) {
class TheException extends Exception {
public TheException ( ) {
}
public TheException ( String message ) {
super ( message ) ;
}
public TheException ( Throwable throwable ) {
super ( throwable ) ;
}
public TheException ( String message, Throwable throwable ) {
super ( message, throwable ) ;
}
}
TheException theExc = new TheException ( "Prefix too short", e ) ;
throw theExc;
}
} catch ( Exception cause ) {
System.err.println ( "Cause: " + cause ) ;
System.err.println ( "OriginalCause: " + cause.getCause ( ) ) ;
}
public String getLocalizedMessage()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1324]Why is a getLocalizedMessage introduced and not a getNativeMessage?
By Anonymous on 2005/03/03 09:02:32 Rate
I would assume that default you want to show localized messages to end-users. So why is a getLocalizedMessage introduced and not a getNativeMessage?
Now programmers have to remember to call getLocalizedMessage by default instead of getMessage, which seems more natural.
public String getMessage()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public StackTraceElement[] getStackTrace()
- See Also:
printStackTrace()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[258]Manually displaying the stack trace
By Anonymous on 2003/05/17 14:07:31 Rate
//Manually displaying the stack trace
StackTraceElement elements [ ] = e.getStackTrace ( ) ;
for ( int i=0, n=elements.length; i < n; i++ ) {
System.err.println ( elements [ i ] .getFileName ( ) + ":" +
elements [ i ] .getLineNumber ( ) + " == > " +
elements [ i ] .getMethodName ( ) +" ( ) " ) ;
}
public Throwable initCause(Throwable cause)
- See Also:
Throwable(String,Throwable)
, Throwable(Throwable)
, IllegalStateException, IllegalArgumentException, getCause()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[9]ArithmeticException
By Anonymous on 2002/07/31 17:40:20 Rate
void TestMeth ( ) {
try {
int x = 3/0;
} //end try block
catch ( ArithmeticException e ) {
Exception ex = new Exception ( "Msg from TestMeth" ) ;
ex.initCause ( e ) ;
throw ex;
} //end catch block
} //end TestMeth
[1243]_
By michael { dot } dever { at } earthlink { dot } net on 2005/01/04 19:21:36 Rate
This is used to give the user a more user friendly exception:
Instead of:
????????????Exception??ex??=??new??Exception ( "Msg??from??TestMeth" ) ;
Do this:
????????????Exception??ex??=??new??Exception ( "Attempting to divide x by 0." ) ;
public void printStackTrace()
- See Also:
fillInStackTrace()
, toString()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void printStackTrace(PrintStream s)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void printStackTrace(PrintWriter s)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1426]Write the stack trace to the string
By joao { dot } carig { dot } com { dot } br on 2005/05/13 09:37:19 Rate
// Create a StringWriter
StringWriter in = new StringWriter ( ) ;
PrintWriter ps = new PrintWriter ( in ) ;
// Write the stack trace to the string
obj.printStackTrace ( ps ) ;
// get the string
StringBuffer output = in.getBuffer ( ) ;
// show the string
System.out.println ( output ) ;
public void setStackTrace(StackTraceElement[] stackTrace)
- See Also:
- NullPointerException,
fillInStackTrace()
, printStackTrace()
, getStackTrace()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Throwable()
- See Also:
fillInStackTrace()
, initCause(java.lang.Throwable)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Throwable(String message)
- See Also:
getMessage()
, fillInStackTrace()
, initCause(java.lang.Throwable)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Throwable(String message,
Throwable cause)
- See Also:
getCause()
, getMessage()
, fillInStackTrace()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Throwable(Throwable cause)
- See Also:
getCause()
, fillInStackTrace()
, PrivilegedActionException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toString()
- See Also:
- Object,
getMessage()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples