.NETGURU
CLR Hosting - exception handling?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.clr.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Vincent Parrett \(Atozed Software\)
Hi

I'm hosting the CLR in my win32 unmanaged application, it's all working
really well however I have one issue left to resolve. When a managed
exception is raised, it is propagated to the win32 host as an ole exception.
Is there a way to get access to the managed exception object (I want to get
access to the stack trace)? It seems the com interop is changing the way
unhandled exceptions are dealt with, setting
AppDomain.CurrentDomain.UnhandledException (in managed code) has no effect,
my handler method is never called. Is there a way to override how com
interop deals with managed exceptions?

--
Regards

Vincent Parrett
Atozed Software http://www.atozedsoftware.com
My blog : http://blogs.atozed.com/vincent
----------------------------------------
Automate your Build Process with FinalBuilder

Reply to this message...
 
    
Vincent Parrett \(Atozed Software\)
Ok, I'm getting closer to a solution. I found that I can call GetErrorInfo
in my win32 host and the QueryInterface on the IErrorInfo reference for the
CLR Exception interface in mscorlib. This works because when hosting the clr
interop is involved and the CCW automatically does the SetErrorInfo when a
managed exception is thrown. This gives me access to the real exception
information and the stack trace, well almost...

The issue I have now is that if the exception is thrown in an AppDomain that
I created from my win32 host, the StackTrace property of the exception
object always returns an empty string. If the exception is thrown from the
default AppDomain then I get the StackTrace ok. I suspect this is an
interface marshalling issue, but I don't have a clue how to resolve this. I
really don't want to have to load my assemblies into the default AppDomain
as I would like to be able to unload/reload the assemblies without having to
restart the app.

Any clues?

--
Regards

Vincent Parrett
Atozed Software http://www.atozedsoftware.com
My blog : http://blogs.atozed.com/vincent
----------------------------------------
Automate your Build Process with FinalBuilder

Reply to this message...
 
    
Nadav (VIP)
Here is the code

#import <mscorlib.tlb>
....
....
....
try
{
...
}
catch(_com_error &e)
{
hr = e.Error();
mscorlib::_ExceptionPtr Exception = e.ErrorInfo();
if(Exception)
{
char *bstrMessage = new char[Exception->ToString.length() + MAX_PATH];
sprintf(bstrMessage, "%s\nPress any key to terminate...\n",
(char*)Exception->ToString);
if(bConsole)
{
printf(bstrMessage);
getch();
}
else
MessageBoxA(0, bstrMessage, "The program has generated an unhandled
exception", MB_OK);
delete bstrMessage;
bstrMessage = 0;
}
}

"Vincent Parrett (Atozed Software)" wrote:

[Original message clipped]

Reply to this message...
 
 
System.AppDomain
System.Diagnostics.StackTrace




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification