I recently came across a code written by a fellow programmer in which he had a try catch statement inside a catch!
Please forgive my inability to paste the actual code, but what he did was something similar to this
try
{
//ABC Operation
}
catch (ArgumentException ae)
{
try
{
//XYZ Operation
}
catch (IndexOutOfRangeException ioe)
{
//Something
}
}
I personally feel that it is one of the poorest code I have ever seen! On a scale of 1 to 10...how soon do you think I should go and give him a piece of my brain? Or am I over-reacting?
EDIT: What he is actually doing is that in the catch, he is performing some other operations which can/should be done when the initial try fails. My problem is with having a clean code and maintainability. Delegating the exception from the first catch to a different function or the calling function would be OK, but adding more code which may or may not throw an exception into the first catch, is what I felt was not good. I try to avoid multiple stacked "if-loop" statements, I found this equally bad.
- IvarD