locked
How to disable CLR exception handling? RRS feed

  • Question

  • Hello forum,


    I got a C++ .NET 2.0 application which has some severe bugs that lead to the application's crash and the loss of all data. To this end I encapsulated the Application::Run( Form^ ) command in main() with a try-catch clause in which the app tries to backup its data and finally displays the call stack.

    Everything works fine with that try-catch clause if (1) I'm launching the app inside VS2005 or (2) the machine on which the app is running has not Visual Studio installed on it. However, if I run my app on a machine with VS (but I run the app from outside the IDE!), my try-catch clause is not even executed -- instead, the .NET runtime shows up with a dialog displaying the exception which occured. I'm only talking of the Release version of my app.

    Is there any way of disabling this runtime dialog such that my own exception handler in main() is being reached and executed?


    Regards,
    Chris
    Friday, June 27, 2008 6:46 AM

Answers

  • Maybe you're getting unmanaged exceptions.

    In the catch, don't specify the type:

    try
    {
        Application::Run( Form^ )
    }
    catch
    {
        // catch non-CLS exceptions as well
    }

    Cheers.
    .: Valeriano Tórtola - MCPD:Windows Developer 2.0 :.: http://www.vtortola.net :.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:55 AM
    Friday, June 27, 2008 11:16 AM
  • Weird stuff, getting the dialog is the normal behavior.  You should get that whether or not VS is installed and in both the Debug and Release builds.  You can disable it with Application.SetUnhandledExceptionMode().  That dialog is not shown if you run in the app in VS, the debugger automatically breaks at the statement that throws the exception.  That's a Good Thing, it lets you debug the cause of the exception.  Saving data after an unhandled exception occurred is questionable, the data is likely to be corrupted.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:55 AM
    Friday, June 27, 2008 11:45 AM

All replies

  • Not to my knowledge.

    The correct way to handle this is to fix your bugs, not to hide them.

    If you cannot fix the bugs because it is in a binary with no source code, rewrite the code.

    However, the exception dialog should only pop up for unhandled exceptions.

    http://presentationmode.blogspot.com/
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, June 27, 2008 8:03 AM
  • Maybe you're getting unmanaged exceptions.

    In the catch, don't specify the type:

    try
    {
        Application::Run( Form^ )
    }
    catch
    {
        // catch non-CLS exceptions as well
    }

    Cheers.
    .: Valeriano Tórtola - MCPD:Windows Developer 2.0 :.: http://www.vtortola.net :.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:55 AM
    Friday, June 27, 2008 11:16 AM
  • Weird stuff, getting the dialog is the normal behavior.  You should get that whether or not VS is installed and in both the Debug and Release builds.  You can disable it with Application.SetUnhandledExceptionMode().  That dialog is not shown if you run in the app in VS, the debugger automatically breaks at the statement that throws the exception.  That's a Good Thing, it lets you debug the cause of the exception.  Saving data after an unhandled exception occurred is questionable, the data is likely to be corrupted.
    Hans Passant.
    • Marked as answer by Bruno Yu Tuesday, July 1, 2008 3:55 AM
    Friday, June 27, 2008 11:45 AM