| 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: 9955
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
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.
|
 |
 |
|
|
subject: Method with throws Exception in declaration
|
|
|