try { // statement which may throw an exception; } |
catch(Exception_type object) { //exception handling statements; } |
finally { // statement to be executed after try block; } |
throw new Exception_class; |
type method_name(parameters) throws list_of_exceptions; |
Note : While handling exceptions using multiple catch block , the superclass type exceptions should come after subclass type exceptions else the subclass type catch block will never be reached. For example : Exception is a superclass of all the subclass exceptions , hence it should come after subclass type catch block. catch(Exception e){ System.out.println(“Exception Caught”); } catch(NullPointerException e1){ System.out.println(“Null Pointer Exception”); }
catch(NullPointerException e1){ System.out.println(“Null Pointer Exception”); } catch(Exception e){ System.out.println(“Exception Caught”); } |
1) Exception() ; // Exception with no description 2) Exception(String param); // Exception with description |
For example : Converting “A” to numeric format will throw this exception.
For example : Suppose we have a String s = null and if we try to find its length using s.length() , this exception will be thrown.