Exception Handling Throwable Error Exception Checked Exceptions Runtime
Exception Handling Throwable Error Exception Checked Exceptions Runtime Exceptions Unchecked Exceptions 1
Exception indicates that a problem occurred but it is not a serious problem. An exception is an abnormal condition that arises in a code sequence at run time. Runtime Exception: It is reserved for exceptions that indicate incorrect use of API. Unchecked Exceptions: Most exceptions are derived from Runtime Exception are automatically available and they need not be included in try – catch block or in any methods throws list. Ex: Arithmetic. Exception Array. Index. Out. Of. Bounds. Exception Array. Store. Exception Negative. Array. Size. Exception Number. Format. Exception Null. Pointer. Exception Jeevan Nagendra 2
Unchecked Exceptions class excep 1 { public static void main(String ar[]) { int a=10; int b=0; try { a=a/b; System. out. println("This will not be printed"); } catch(Arithmetic. Exception ae) { System. out. println("Division by 0 error. . . change the value"); } System. out. println("Quittting"); } }
Checked. Exceptions: Checked. Exceptions must included in try-catch or in a methods throws list. Ex: Class. Not. Found. Exception IOException SQLException No. Such. Method. Exception etc. , Jeevan Nagendra 4 be
Checked Exceptions public class excep 3 { public static void main(String ar[]) { try { Class c=Class. for. Name(ar[0]. trim()); String name=c. get. Name(); Class sc=c. get. Superclass(); String sname=sc. get. Name(); System. out. println("Name is : "+name+" and Super. Class name is : "+sname); } catch(Class. Not. Found. Exception cnf) { } } } System. out. println("No such Class");
- Slides: 5