[2 / 1 / ?]
Quoted By:
What is output by the following code? (Assume there is a class NegativeNumberException defined in this package.)
public static void main(String[] args) {
try {
int num = 99;
sampleMethod(num);
} catch(Exception ex) {
System.out.print("CaughtMain");
}
}
public static void sampleMethod(int n) throws Exception {
try {
if(n>0)
throw new Exception();
else if(n<0)
throw new NegativeNumberException();
else
System.out.print("Good");
System.out.print("InSample");
}catch(NegativeNumberException ex) {
System.out.print("CaughtSample");
} finally {
System.out.print("InFinal");
}
System.out.print("AfterFinal");
}
}
2. What if it was
int num = -99;
3. What if it was
int num = 0;
public static void main(String[] args) {
try {
int num = 99;
sampleMethod(num);
} catch(Exception ex) {
System.out.print("CaughtMain");
}
}
public static void sampleMethod(int n) throws Exception {
try {
if(n>0)
throw new Exception();
else if(n<0)
throw new NegativeNumberException();
else
System.out.print("Good");
System.out.print("InSample");
}catch(NegativeNumberException ex) {
System.out.print("CaughtSample");
} finally {
System.out.print("InFinal");
}
System.out.print("AfterFinal");
}
}
2. What if it was
int num = -99;
3. What if it was
int num = 0;