permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question about exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question about exception" Watch "a question about exception" New topic

a question about exception

Simo Hayha

Joined: Jul 02, 2002
Posts: 19
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

Joined: Aug 05, 2002
Posts: 787
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

Joined: Aug 26, 2001
Posts: 7610
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();

[Blog] [Blogroll] [My Reviews] My Linked In
It is sorta covered in the JavaRanch Style Guide.
subject: a question about exception
Similar Threads
Runtime exception
Which one to throw??
Help me friends. I'll appreciate your answer.(Exceptions)
override and overload method
Marcus Green - Qn : 23 - Doubt