Control flow in try-catch-finally
Example:
class Test
{
public static void main(String[] args)
{
try
{
System.out.println("statement1");
System.out.println("statement2");
System.out.println("statement3");
}
catch(Exception e)
{
System.out.println("statement4");
}
finally
{
System.out.println("statement5");
}
System.out.println("statement6");
}
}
Case 1: If there is no exception. 1, 2, 3, 5, 6 normal termination.
Case 2: if an exception raised at statement 2 and corresponding catch block matched. 1,4,5,6 normal terminations.
Case 3: if an exception raised at statement 2 and the corresponding catch block is not matched. 1,5 abnormal termination.
Case 4: if an exception raised at statement 4 then it’s always abnormal termination but before the final block will be executed.
Case 5: if an exception raised at statement 5 or statement 6 its always abnormal termination.
Comments
Post a Comment