We have an unusual case, a try-catch block inside another try-catch block. Both catch clauses catch Exception type of exceptions. Error that occurs in the most inner try-catch block, gets caught byt the first catch that is empty and instead of moving to the next line, it gets caught another time by the other catch. This is something I have never seen before. One of our colleagues claims that this is some setting but he does not remember what kind of setting. Do you know why is this happening and how to “turn it off”?
Please find the code below:
try {
//some code
try
{
//code that throws exception
}
catch (Exception)
{
}
//some other code, never reached
}
catch (Exception ex)
{
Logger.Write(ex.ToString());
return null;
}
One thing that could be causing this is that your first catch block is also throwing an exception. This would cause the second one to be triggered.
Your colleague may be referring to the exception catching functionality of Visual Studio which allows you to break on any exceptions including ones that have already been handled. You can find this by pressing CTRL + ALT + e, or in the menus it’s listed under Debug –> Extensions…
If neither of those are the case then we’ll need more code