Page 1 of 1

About Question enthuware.ocajp.i.v7.2.841 :

Posted: Sun Sep 08, 2013 10:50 am
by yurifw
this is the method i have:

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
then i change to the following:

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();
}
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.

Re: About Question enthuware.ocajp.i.v7.2.841 :

Posted: Sun Sep 08, 2013 10:56 am
by admin
The question asks you to make your method compile i.e. the method a() in your example, Not some other method i.e. main() in your example. In your example, the problem exists in main not in a().

In other words, the question does not say that there is a main method that calls your method and you need to make everything compile.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.841 :

Posted: Mon Sep 09, 2013 7:46 pm
by yurifw
ok then, thanks,
interpretation can be tricky