public class UsingExceptions {
public static void main(String[] args) {
try{
throwException();
}
catch(Exception e){
System.err.println("Exception handled in main");
}
doesNotThrowException();
}
public static void throwException()throws Exception{
try{
System.out.println("Method throwException");
throw new Exception();
}
catch(Exception e){
System.err.println("Exception Handled in Method throwExceptioin ");
throw e;
}
finally{
System.err.println("Finally executed in method throwException");
}
}
public static void doesNotThrowException(){
try{
System.out.println("Method doesNotThrowException");
}
catch(Exception e){
System.err.println("Exception handled in method doesNotThrowException");
}
finally{
System.out.println("finally executed in doesNotThrowException");
}
System.out.println("end of method doesNotThrowException");
}
}
My IDE is outputting:
- Method throwException
- Exception Handled in Method throwExceptioin
- Method doesNotThrowException
- Finally executed in method throwException
- Exception handled in main
- finally executed in doesNotThrowException
- end of method doesNotThrowException
but I'm expecting:
- Method throwException
- Exception handled in method throwException
- Finally executed in throwException
- Exception handled in main
- Method doesNotThrowException
- Finally executed in doesNotThrowException
- End of method doesNotThrowException
Where is my problem?