The code example you have given isn't the most useful in my opinion. Haveing
nested try-catches is useful if you are actually going to do something with
the exception in the first catch (e.g. some cleanup - but this should really
be done in a finally)... in your example below your first catch statement is
doing nothing and the only result is that it is slowing your application down
in situations where an exception is thrown.
Actually, in your example you are doing nothing at all with the exceptions
in either catch so I'd question why they are being caught at all... other
then to make it appear that a different method threw it.
If you have shown something like the following then it's perfectly fine and
needed in my opinion:
try {
try {
}
catch(...){
// Only catch if you're going to do something with it
}
finally{
// do some cleanup here
}
}
catch(Exception ex){
// Do something with the exception and then throw it up the stack if you
want.
throw;
}
"Arjen" wrote:
Hi,
I'm doing this:
try {
try {
}
catch(Exception ex){
throw;
}
}
catch(Exception ex){
throw;
}
Is a nestled try-catch-throw useful? Or is one enough?
Thanks!