dear helpers,
1)What means exception.toString() and why must use throws Runtime Exception rather than the catch statement based on this program...?
public class Test {
public static void method3()throws RuntimeException{
throw new RuntimeException("RuntimeException occured in method3");
}
public static void method2()throws RuntimeException {
try{
method3();
}catch(RuntimeException exception){
System.out.printf("The following exception occured in method2\n%s\n",exception.toString());
throw exception;
}
}
public static void method1()throws RuntimeException{
try{
method2();
}catch(RuntimeException exception){
System.out.printf("The following exception occured in method1\n%s\n",exception.toString());
throw exception;
}
}
public static void main(String[] args){
try{
method1();
}
catch(RuntimeException exception){
System.out.printf("The following exception occured in main\n%s\n",exception.toString());
}
}
}