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)
{
Logg开发者_Python百科er.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
Try cleaning the //handling to do nothing and see if it's still occur if so the //handling section is either causing an exception or throw the exception
I have two followups:
Does this happen only on your vs or on others as well ?
- if this happens only on yours - it probably is Ctrl+Alt+E, setting up the debugging and breaks
Are you running an exception block ? maybe your exception handling block is malconfigured ?
You could try using a finally block instead of writing your "other code" after the try-catch block
精彩评论