Wednesday 18 December 2013

Exception Handling Example.

Question 1
Try
{
   return 5;
}
catch(Exception Ex)
{
    return 6;
}
finally
{
    return 7;
}

What is output of following code?
Ans: Error Control cannot leave the body of a finally clause.  You get above error message. But if you run this code in Java, You get output 7.

----------------------------------------------------------------------------------------------------
Question 2
Try
{
   return 5;
}
catch(Exception Ex)
{
 }
finally
{
 }
What is output of this code? 
Ans: 5. But You run this same code in Java it get the Error, Because finally  has not return statement.

No comments:

Post a Comment