Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about exception

 
Simo Hayha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why does the following code can not compile?
public void amethod()throws IOException{
throw new ProtocolException();
}
can can a method throws Excepton? like this:
public void amethod()throws Exception
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There:
I guess error is because amethod declaration says
that it can throw one kind of exception while it
actually throws another kind in the method body...
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error message you get when compiling your class? Something like
unreported exception ProtocolException; must be caught or declared to be thrown
throw new ProtocolException();
??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic