Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method with throws Exception in declaration

 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you have like



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

Thanks,

Justin
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are this and this interview/book questions?

Did you give it a try?
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind.
Make sure you test them actually because we may lie but compiler won't.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic