Wednesday, 4 September 2019

Exception handling


Exception is an event which will terminate program unexpectedly.

Two types of exceptions

Checked Exceptions
Exceptions which are identified by the java compiler.

InterruptedException
IOExceptin
FileNotFoundException

Un-Checked Exceptions
Exceptions which are not identified by the java compiler.

Arithmetic Exception
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException

Handling Exceptions

Syntax1:

try
{
statements;
}
catch(Exception Type)
{
statements;
}

Syntax2:

try
{
statements;
}
catch(Exception Type1)
{
statements;
}
catch(Exception Type2)
{
statements;
}
catch(Exception Type3)
{
statements;
}

Syntax3:

try
{
statements;
}
catch(Exception Type1)
{
statements;
}
finally
{
statements;
}

finally block is always executes:
1.Exeption doesn't occur
2.Exception occurs and not handled
3.Exception occurs and handled.

Checked Exception can be handled by 2 ways
1.try..catch
2.throws keyword

No comments:

Post a Comment