Visual Studio 2012 RC breaks on exceptions from within the .NET Framework. How do I make it break on exceptions only in my code?

99封情书 提交于 2020-01-01 08:48:27

问题


When debugging using Visual Studio 2012 RC with break on exception turned on, Visual Studio breaks on exceptions from within the .NET Framework. How do I make it break on exceptions only in my code?

When debugging a ASP.NET MVC 4 project there are a lot of framework exceptions thrown on every page hit. The following exception happens a lot:

System.Globalization.CultureNotFoundException occurred
  HResult=-2147024809
  Message=Culture is not supported.
Parameter name: name
UserCache is an invalid culture identifier.
  Source=mscorlib
  ParamName=name
  InvalidCultureName=UserCache
  StackTrace:
       at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
  InnerException: 

This exception is coming from within mscorlib.dll which I do not not want Visual Studio to break on.

It looks like I am missing a column in the exceptions window. I only see the "Thrown" column and "User-Unhandled" is missing. This might be my issue.


回答1:


I believe all you need to do is go to

Debug -> Options -> Debugging and check Enable Just My Code (Managed Only)




回答2:


Go to Debug -> Exceptions and untick everything. This will tell the debugger to break only on exceptions which are not handled. Unhandled exceptions are ones which are not 'caught', which do not happen within an appropriate try/catch.

But understand that whichever type of exception happens, if it is not handled, either the debugger will break or application will exit. That's how it's supposed to work. If you expect the exception to happen, wrap culprit code in appropriate try/catch block.

In this case that would be

try
{
...
}
catch (CultureNotFoundException ex)
{
   // Show your own message here, or otherwise handle the exception
}


来源:https://stackoverflow.com/questions/11741968/visual-studio-2012-rc-breaks-on-exceptions-from-within-the-net-framework-how-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!