Thursday, 12 December 2013

Multiple exception handling in a single catch block

The earlier versions of java had multiple catch block one after the other where we can handle several exceptions in one try and multiple catch block as follows:

try
{
//do someting;
}
catch(Exception1 e)
{
handleException(e)
}
catch(SQLException e)
{
handleException(e)
}

Java 7 has introduced the new feature of adding multiple exception objects in one catch block as below.

try
{
//do someting;
}
catch(Exception1, Exception2 e)
{
handleException(e)
}

This feature thereby reduces the overhead on the developer .

No comments:

Post a Comment