[My Blog]
All roads lead to JavaRanch
Originally posted by Satou kurinosuke:
KJ,
did you actually try to compile it ?
Originally posted by Satou kurinosuke:
I'd like to add that if tryThis would throw IOException too, it would compile.
But this was not stated in the problem above.
import java.io.*;
public class Excep {
public static String s = "";
public static void main(String[] args) {
try {
tryThis() ;
return;
} catch (java.io.IOException x1) {
System.out.println("exception 1") ;
return;
} catch (Exception x2) {
System.out.println("exception 2") ;
return;
} finally {
System.out.println("finally") ;
}
}
public static void tryThis() throws IOException {
if(s.equals("IO")){
throw new IOException();
}
else {
throw new NumberFormatException();
}
}
}
Originally posted by Sandeep MP:
I wrote a small program using the code snippet given.
The program follows
Now when I tried to compile it, I got a compile time error saying
CheckedException.java:13: exception java.io.IOException is never thrown in body of corresponding try statement
} catch (IOException x1){ ^
I feel that the options for the question stated is wrong.
Hope this helps !!!
Cheers,
Sandeep
Lookout! Runaway whale! Hide behind this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|