as

Thursday 27 June 2013

What are the Categories of Exceptions in JAVA

There are 3 categories of Exceptions in JAVA.



  • Checked exceptions:  These exceptions can be found at the time of compilation. For example class not found, method not found


  • Runtime (Unchecked) exceptions: A runtime exception is an exception that can be ignored at the time of compilation. For example - array index out of bound, divide by zero error.


  • Errors: Can not be found at the time of compilation. Here Programmer has no control over these kinds of exceptions. For example JVM running out of memory.


If a method does not handle a checked exception using try catch blocks, the method must declare it using the throws keyword. 

Here is the syntax of Method that throws exception.

public void dosomething(int a ) throws  IOException
 {

 // Method code

 throw new IOException();

 }


Finally block is used along with try catch blocks. Code in finally block is executed regardless of whether exception occurs or not.







No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis