Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Method with throws Exception in declaration  RSS feed

 
Ranch Hand
Posts: 802
  • 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
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • 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.
 
Ranch Hand
Posts: 1374
  • 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
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!