Tuesday, May 27, 2008

Exceptions :
1.
public static int returnTest(){
try{
return 1;
}
catch(Exception e){
return 2;
} finally{
return 3;
}
}
What will returntest method return???

Ans : is 3.

If we have finally block it will always get called .
If we remove the finally block if will print 1.


2.
public class Test6
{
public static void main(String args[]) throws Exception{
try{
throw new Exception();
} finally{
System.out.println("No Error");
} }}
Here it will print No Error followed by java.lang.Exception.