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

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.

Answers


I believe all you need to do is go to

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


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
}

Need Your Help

Push Notifications in Android Platform

android push alerts

I am looking to write an app that receives pushed alerts from a server. I found a couple of methods to do this.

Remove all All Elements not working

c# list collections

I noticed this function in a .NET project I am working on.