• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java question

Bluga

Banned
class ExceptionTest{
public static void main(String args[]){
try{
methodA();
}catch(IOException e){
System.out.println("caught IOException");
}catch(Exception e){
System.out.println("caught Exception");
}
}

public void method(){
throws IOException();
}
}

If methodA() throws a IOException, what is the result?

Why the program doesn't complie?

 
Originally posted by: Bluga
class ExceptionTest{
public static void main(String args[]){
try{
methodA();
}catch(IOException e){
System.out.println("caught IOException");
}catch(Exception e){
System.out.println("caught Exception");
}
}

public void method(){
throws IOException();
}
}

If methodA() throws a IOException, what is the result?

Why the program doesn't complie?

If that is your exact code and you didn't type something wrong then it needs to be

public void methodA(){
throws IOException();
}


You just left the A off the end of the method. If that isn't it, could you post the actual error message you are getting?

 
It has to be:

public void methoda() throws IOException
{
}


Notice that throws clause isn't inside the brackets.
 
Originally posted by: Argo
It has to be:

public void methoda() throws IOException
{
}


Notice that throws clause isn't inside the brackets.

Absolutely correct. I can't believe I missed that. 🙂

 
Back
Top