Forums Register Login

Exception handling

+Pie Number of slices to send: Send
Hi sir,
I am using a try{ some code} and then finall{some code} block.I am not using catch block.So if an exception is thron in try block,how to handle it.
+Pie Number of slices to send: Send
 

pratapsiva sivakumar wrote:Hi sir,
I am using a try{ some code} and then finall{some code} block.I am not using catch block.So if an exception is thron in try block,how to handle it.



I believe the way you are doing it is the same as catch( Exception e ) {...}, except you don't get an exception object to work with. So youhave to make up your own message.
+Pie Number of slices to send: Send
You should either declare or manipulate it inside of the caller method
+Pie Number of slices to send: Send
 

Filipe Pinheiro wrote:You should either declare or manipulate it inside of the caller method
...



Hold on. If anything ever gets thrown in that situation, that means my answer that a finally is like a catch without the exception object to work with must be wrong.

Filipe, do you see any possible value in having a try without a catch?
+Pie Number of slices to send: Send
Any checked exception must either be caught or declared to be thrown. So if you don't catch it, throw it on:
+Pie Number of slices to send: Send
Thanks Rob for the example. I hadn't considered that there could be an exception other than that caused by a non-existent file.

I guess there might be a reason why you would want one or both exception types to be handled further up the stack, and still deal with closing the Reader within its scope. hence the try without a catch. Which means of course there is a reason for declaring the reader locally as opposed to passing the reader instead of the file name to this method.

regards.
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1008 times.
Similar Threads
Declare String Variable Outside of Try Block
How to decide whether to use try/catch to handle the exception or throws to declare the exception
Code execution logic
File Won't Delete
NamingException: Failed to initialize the ORB
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:03:38.