File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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
I agree. Here's the link:
subject: a question about exception
jQuery in Action, 3rd edition