Connecting Tech Pros Worldwide Help | Site Map

Handling unmanaged exceptions in managed code

Newbie
 
Join Date: Jan 2008
Posts: 7
#1: May 21 '09
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 UnhandledExceptionEventHandler and ThreadExceptionEventHandler....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 PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 700
#2: May 21 '09

re: Handling unmanaged exceptions in managed code


Have a
Expand|Select|Wrap|Line Numbers
  1. Catch
  2. {
  3. // catch unmanaged exceptions here
  4. }
  5.  
for unmanaged exceptions... Catch{} catches all exceptions .. both unmanaged and managed
Newbie
 
Join Date: Jan 2008
Posts: 7
#3: May 21 '09

re: Handling unmanaged exceptions in managed code


.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..??
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 700
#4: May 21 '09

re: Handling unmanaged exceptions in managed code


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...
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 700
#5: May 21 '09

re: Handling unmanaged exceptions in managed code


Check these links Consuming Unmanaged DLL Functions and Map HRESULTs and Exceptions
Reply

Tags
unmanaged exceptions