Forums Register Login

try and catch

+Pie Number of slices to send: Send
Does having 4 to 5 try/catch blocks in a method slows down the execution of the method ?
+Pie Number of slices to send: Send
No, unless the exceptions are thrown in the common cases.

The real question I have is why would you ever have a function with 5 try/catch blocks? Are they the same exception? If so, why not group them as one? If they are different they should probably be in separate functions, lest a single function is one long set of try/catch blocks. I could understand one try with 5 different catches, thats perfectly valid.

Also, it is a general practice not to catch Runtime exceptions unless your on the top-most level of a delegate. Finally, if you can avoid throwing exceptions in the first place (for example checking for an object equal to null rather than catching a null exception) it is always preferable to do so since there will be a performance hit if the exception is thrown versus avoiding the exception.
[ November 08, 2005: Message edited by: Scott Selikoff ]
+Pie Number of slices to send: Send
No. Throwing exceptions is expensive. But try/catch blocks themselves are essentially free when no exceptions are thrown.
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 647 times.
Similar Threads
Please Help with the flow of this code
Overriding doubt in K&B
throws Vs try..catch
handling error when using jsp:include
Generate pdf file and display in a browser
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:03:29.