locked
Why show the dialog "Run-Time Check Failure. If there is a handler for this exception, the program may be safely continued." when Debugging

    Question

  • Hi all,

    I have one problem for catch exception.

    try
    {
    	int* a1;
    	int a2;
    	a2 = *a1 +1;
    }
    catch(Exception^ e)
    {
    	OutputDebugString(L"Get Exception ");
    }
    catch(...)
    {
    	OutputDebugString(L"Get All Exception");
    }
    Because a1 doesn't initialize, it should be capture this exception and show "Get Exception"  or  "Get All Exception"

    But, it doesn't.

    The actual result is this:

    How to change setting for disappear this dialog?
    I want survey the try-catch workflow

    Thanks

    Monday, May 21, 2012 9:32 AM

All replies

  • Access violations aren't automagically converted to C++ exceptions.

    You don't have a line of code that throws a C++ exception, so there is no catch that could catch this.

    You'll just have to make sure you initialize your pointers and do the proper nullptr checks.


    http://www.iconstructions.be


    • Edited by Nico Vuyge Monday, May 21, 2012 3:08 PM
    Monday, May 21, 2012 3:08 PM
  • That dialog occurs when you break on the first chance exception, which occurs immediately when the exception is raised before it can be caught. If you push continue then it should go on to your catch statement rather than crashing. This is often useful so that the catch statement doesn't hide crashes that you want to debug and fix before shipping. In your case where you want to get to the catch statement you can turn off the first chance exception handling. In the dialog uncheck "Break when this exception type is thrown" or go to the Exception Settings dialog and uncheck the Thrown column for the exception type you don't want to break on.

    --Rob

    • Marked as answer by woody tk Tuesday, May 22, 2012 2:24 AM
    • Unmarked as answer by woody tk Tuesday, May 22, 2012 4:16 AM
    Monday, May 21, 2012 4:12 PM
    Owner
  • Hi Rob,

    I have uncheck all the exception throw from Debug->Exceptions...(Ctrl+Alt+E)
    But it still show the dialog and doesn't run the catch area.

    I also try to set the solution Configurations to Release, but it's not useful.

    Thanks

    --------------------------------------------------------------------------------------

    Hi Nico,

    I know that I can using nullptr check to do it.
    But I think the exception also can handle this situation( ex : NullReferenceException)

    Thanks

    Tuesday, May 22, 2012 4:48 AM
  • By default these exceptions are not catched by catch(...). You'd have to use the /EHa compiler switch, see http://msdn.microsoft.com/en-us/library/1deeycx5.aspx

    I think it's a bad idea to use this to let your program struggle on with a corrupt memory situation.


    http://www.iconstructions.be

    Tuesday, May 22, 2012 5:47 AM