About Question enthuware.ocajp.i.v7.2.841 :
Posted: Sun Sep 08, 2013 10:50 am
this is the method i have:
then i change to the following:
if I declare that method a throws IOException, I would have to handle it when it is called, and the answer doesn't say anything about changing other parts of the code, so why is it correct? in the example above, declaring the throws clause still doesn't make it compile.
Code: Select all
public static void main (String [] args){
a();
}
public static void a(){
//non-throwing exception code...
}
public static void b() throws IOException{
throw new IOException();
}
//no compilation error
Code: Select all
public static void main (String [] args){
a(); //compilation error, unhandled exception
}
public static void a() throws IOException{
//not throwing exception code...
b();
}
public static void b() throws IOException{
throw new IOException();
}