I tried out following code ...
public class Ex3
{
void method()throws MyException
{
try {
throw new MyException("UnExpected Conditions!");
}
catch(MyException e){
System.out.println("In the method -caught- " + e);
throw new MyException("Exception thrown from catch block");
}
finally
{
System.out.println("finally in the method...");
throw new MyException("Exception thrown from finally block");
}
}
public static void main(
String args[]){
Ex3 o = new Ex3();
try {
o.method();
}
catch(MyException e)
{
System.out.println("caught- " + e);
}
System.out.println("exiting main...");
}
}
class MyException extends Exception
{
public MyException(){}
public MyException(String msg){
super(msg);
}
}
The o/p is
In the method -caught- MyException: UnExpected Conditions!
finally in the method...
caught- MyException: Exception thrown from finally block
exiting main...
What happens about Exception thrown by catch block in the method? Catch in main catches the exception thrown by finally block in method. Who handles the Exception thrown by catch block in method?
Rashmi