File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Method with throws Exception in declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method with throws Exception in declaration" Watch "Method with throws Exception in declaration" New topic
Author

Method with throws Exception in declaration

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
when you have like



does this require you to do a try/catch/finally everytime
you call this method?

Thanks,

Justin


You down with OOP? Yeah you know me!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10906
    
  12

no.

well, not exactly.

you have to either catch and handle the exception, or re-throw it. i could do this:




so while i am not explicitly using a try/catch/finally, whatever calls my cook() method has to... or has to re-throw it.

SOMETHING SOMEWHERE will have to catch the exception, but it may not be anything you ever wrote.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Are this and this interview/book questions?

Did you give it a try?
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
when i get home i'll actually start testing some of this stuff out, but from the example I didn't know
whether adding 'throws IOException' or any other exception required the caller of that function
to do a try/catch or not.

But now I see that you can also call that function inside another that throws the general exception
'throws Exception' or the same, or a sub-exception of the original.

Thanks,

Justin

P.S
I'm just running through the SCJP study guide and I'm asking questions of things I'm not 100% on.
I really want to get a grasp of this and get my Certs. Now that I have graduated and have more
free time on my hands I can actually study for this more.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Never mind.
Make sure you test them actually because we may lie but compiler won't.
 
jQuery in Action, 2nd edition
 
subject: Method with throws Exception in declaration
 
Similar Threads
Question about exception
Exception handling
Difference between Throws and Throw
Difference
Exception Doubt pls help