Java Codes
Beginners
Core Java
Date Time
Java2D
Java Applets
Java AWT
Mathematics
Networking
Servlets
Session
Sound
Swing
Threads
Util Package
JDBC
Learning
Other
Security
XML
Java > Core Java sample source codes
Using Exceptions
Using Exceptions public class UsingExceptions { public static void main( String args[] ) { try { throwException(); } catch ( Exception e ) { System.err.println( "Exception handled in main" ); } doesNotThrowException(); } public static void throwException() throws Exception { // Throw an exception and immediately catch it. try { System.out.println( "Method throwException" ); throw new Exception(); // generate exception } catch( Exception e ) { System.err.println( "Exception handled in method throwException" ); throw e; // rethrow e for further processing // any code here would not be reached } finally { System.err.println( "Finally executed in throwException" ); } // any code here would not be reached } public static void doesNotThrowException() { try { System.out.println( "Method doesNotThrowException" ); } catch( Exception e ) { System.err.println( e.toString() ); } finally { System.err.println( "Finally executed in doesNotThrowException" ); } System.out.println( "End of method doesNotThrowException" ); } }
Privacy Policy
|
Link to Us
|
Links