<<< Exception chaining | Index | Java assert statement >>> |
A custom exception class that uses exception chaining:
public class MyException extends Exception { public MyException() { } public MyException( Throwable cause ) { super( cause ); } }
Code that throws a MyException with chaining:
catch ( IOException ex ) { throw new MyException( ex ); }
Code that catches MyException and displays the cause:
catch ( MyException ex ) { System.out.println( "MyException: Application Error" ); System.out.println( ex.getCause().toString() ); }
<<< Exception chaining | Index | Java assert statement >>> |