Handling unmanaged exceptions in managed code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sree83
    New Member
    • Jan 2008
    • 7

    Handling unmanaged exceptions in managed code

    Hi All,

    I am having an executable developed in C#.Net. My app make use of services from some unmanaged dlls it loads. My problem is that my application is termainted due to some exceptions within these unmanaged codes. I tried AppDomain UnhandledExcept ionEventHandler and ThreadException EventHandler... .but it fails to catch the excpetions...

    Can anyone tell me how to handle the unmanaged exceptions in manged code in.
    Thanks in advance...
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Have a
    Code:
    Catch
    {
    // catch unmanaged exceptions here
    }
    for unmanaged exceptions... Catch{} catches all exceptions .. both unmanaged and managed

    Comment

    • sree83
      New Member
      • Jan 2008
      • 7

      #3
      .Thanks for the reply...
      But still i am not sure whether the exception is raised when any method is invoked from the managed code...

      There are 2 unmanaged modules in use..one for logging purpose and the other for enabling a communication with another server....Both of them manage a lot of threads within them...

      so where to put the try-catch statement to catch exceptions which may be raised from some other threads within the unamanged app..??

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        You can put the catch{} block in your C# code... Do you have exception handling built within those modules? Things should be cleaner if your module either calls functions or fails with app reason...

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          Check these links Consuming Unmanaged DLL Functions and Map HRESULTs and Exceptions

          Comment

          Working...