Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
1)I want to know that nested try catch is not good?why? i need the reason..

2) visit it also as i think from link

example[]


it could be handle by a try with multiple catches..?
Posted
Updated 15-Jul-12 5:58am
v3
Comments
Kenneth Haugland 15-Jul-12 12:03pm    
Not any reason except readability. I think you would need to have nested try catch blocks sometimes. I usually dont give the in the same try catch, but hide one of them in a function, just so it would look cleaner.
Sergey Alexandrovich Kryukov 15-Jul-12 17:04pm    
Not sometimes, but very often. The questions simply makes no sense and demonstrate some "mental anti-pattern". The whole way of thinking is wrong. I tried to answer, please see...
--SA

Some hints at The Competitors[^] site.
 
Share this answer
 
Using an idiotic code sample does not prove anything. For any valid and useful technique anyone can invent totally idiotic code sample using it, so what?

Nested try-catch blocks are important, that can be very useful, and there are many cases when they are just unavoidable. Besides, from the question, its not clear what do you mean by "nesting", just coding style or functional nesting. I mean, one can use several nested "try" statements in the same method, or inner "try" statements can be carried out of one method into a separate method, which usually improve readability (but even that is not a must).

Now, I don't want to explain any reasons for exception uses, because it's boring and very obvious thing. Why doing that if the whole approach is wrong and the question makes no sense, because the question is based on the assumption that nesting "try-…" blocks are bad.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900