Could someone explain why the code does not compile {error mesg : missing return tatement !!} until the finally clause with "return 0" is added ?
thanks
public class Test_9_3_02_2245 {
public static int testX(int i) {
try { exGenerator(i);
}
catch (ArithmeticException aex) {
System.out.println("Arith : "+aex);
return 1;
}
catch ( NullPointerException nex) {
System.out.println("Null : "+ nex);
return 2;
}
catch (RuntimeException rex) {
System.out.println("Runtime : "+ rex);
return 3;
}
//finally {System.out.println("Finally"); return 0; } }
static void exGenerator(int exType) {
switch(exType){
case 1 : throw new NullPointerException();
case 2 : throw new ArithmeticException();
case 3 : throw new RuntimeException();
default: throw new ArrayIndexOutOfBoundsException();
}
}
public static void main(
String[] args) {
if(args.length!=1) { System.out.println(testX(5));}
if (args.length==1) {
int extype = Integer.parseInt(args[0]);
System.out.println(testX(extype));
}
}
}