![]() |
![]() |
Java Packages | |
Java Built in packages | |
Java Package Access Specifiers |
Introduction of Errors | |
Java Exceptions | |
Java Try Block | |
Java Catch Block | |
Java Finally Block | |
Java Throw Keyword | |
Java Throws Keyword | |
Java Builtin Exceptions | |
User Defined Exceptions |
Java Multithreading | |
Creating a Thread | |
Thread Life Cycle | |
Thread Exceptions | |
Thread Synchronization |
Java Programs | |
Java Keywords Dictionary | |
Java Interview Questions |
All program statements which are going to generate an exception are written inside the try block.
If an exception is found in the try block then it is thrown to particular matching catch block for handling purpose.
If any one statement generates the exception in try block then all other remaining statements are skipped and execution is jumped into the matching catch block.
Syntax
try { // statements which are generating an exception. .... .... .... }
Note : try block should have catch or finally block for handling an exception. We cannot write only try block.
Example
try { int a=25, b=0; int c = a/b; // generates an exception as Divided by zero. System.out.println("Division is : "+c); // compiler skipes this line and jumps into catch block. }