2

I have code in try block which is throwing out of memory exception.. depending on size of input. Problem is that VS is breaking on that line even tough i have it in try/catch block.. so it should be handled.

try
{
    Array arrayND = Array.CreateInstance(typeof(ushort), sqs.Select(n => n.Count).ToArray());
}
catch (Exception e)
{
    MessageBox.Show("Input is too big. Please limit number of sequences or there length.");    
}

Is it possible to set visual studio so it would not break on code in try block when exception is thrown? thanks.

Martin877
  • 263
  • 2
  • 10

1 Answers1

1

In the menu, goto Debug --> Windows --> Exception Settings.

From the opened window, notice the Common Language Runtime Exceptions category. You can uncheck the whole category, or, if you expand the category, you can uncheck only the exception types you don't want VS to break on.

Little side note: beware about trying to handle OOM exceptions like any other exception. See here for more information: When is it OK to catch an OutOfMemoryException and how to handle it?

Community
  • 1
  • 1
sstan
  • 35,425
  • 6
  • 48
  • 66
  • 1
    If i disable for example out of memory exc. this way, than it will ignore all occurrences and not just in try catch block. – Martin877 Aug 13 '15 at 21:45
  • Not sure I understand that last statement. If you disable the OOM exception type, then VS will no longer break as soon as it is thrown from anywhere in your project. – sstan Aug 13 '15 at 21:48
  • 1
    I want it to break on thrown OOM anywhere except code in try block. – Martin877 Aug 13 '15 at 21:56
  • I doubt VS would allow something like that to be configured. It would be too difficult and costly for VS to, on an exception throw, check to see if higher in the call stack there is a statement that is inside your `try` block, to then decide whether to break or not. – sstan Aug 13 '15 at 22:20