Exception :
Exception is an abnormal condition.
Types of Exception :
1.Checked Exception
2.Unchecked Exception
3.Error
1) Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException, SQLException etc. Checked exceptions are checked at compile-time.
2) Unchecked Exception
The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time rather they are checked at runtime.
3) Error
Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.
Exception Handling Keywords
There are 5 keywords used in java exception handling.
try
catch
finally
throw
throws
Example :
Try {
// logic it may throw exception
}Catch(Exception e){
System.out.println(e.getMessage());
}
Exception is an abnormal condition.
Types of Exception :
1.Checked Exception
2.Unchecked Exception
3.Error
1) Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException, SQLException etc. Checked exceptions are checked at compile-time.
2) Unchecked Exception
The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time rather they are checked at runtime.
3) Error
Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.
Exception Handling Keywords
There are 5 keywords used in java exception handling.
try
catch
finally
throw
throws
Example :
Try {
// logic it may throw exception
}Catch(Exception e){
System.out.println(e.getMessage());
}
No comments:
Post a Comment