none
AppDomain.CurrentDomain.UnhandledException not fired in COM object RRS feed

  • Question

  • Hi,

    I have a simple mange COM object (.Net4.0) providing tow methods: Init() and ThrowTestException()
    The init method simply assignes the eventhandler to AppDomain.CurrentDomain.UnhandledException.
    The ThrowTestException throws an exception.

    Then I instantiate this COM exposed class from unmanged code and call Init().
    This works fine, as I can see in stepping throw using VS as debugger.
    But when calling ThrowTestException() afterwards the handler is NOT called. I directly get an OleException in my unmangde code.

    Why does AppDomain.CurrentDomain.UnhandledException not fire?


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Thursday, April 3, 2014 3:21 PM

All replies

  • Hi Harald,

    The unhandled exception is a last-ditch attempt to allow the application to log meaningful information before it is terminated. See http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx. In this case, it’s impossible to handle UnhandledException. The COM interop support code in the CLR implements the restriction in COM that exceptions are not allowed to escape from a COM method. Your method will be called with a catch-all exception handler inside the CLR that catches any exception you throw.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 4, 2014 1:56 AM
    Moderator
  • Hello Herro,

    thank you for your answer. I understand, but if there is this global exception handler in the CCW why does System.Windows.Forms.Application.ThreadException still work? (e.g. for an exception thrown in a key event of a usercontrol)

    And what about the ReliabilityContractAttribute? may that attribute or any other make the CLR fire the UnhandledException event before the CCW handles it?

    All I need is a copy of the execption I can log before the CCW passes it to the COM client.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com


    Friday, April 4, 2014 6:13 AM