Non-MFC exception handling

Started by
7 comments, last by d000hg 19 years, 2 months ago
I've found a point where an exception is generated in my application on a few people's machines. It seems to be occurring as a function returns rather than in any code which is executed which is odd in itself - any thoughts on that? Because this is a non-MFC project, CException isn't available to me I think. So other than catch(...), what can I do to find what the exception is? clarification: If I wrap the offending function call in a try block, followed by catch(...), this catch block is triggered. However this gives me no information about the exception, just that it happened! Thankyou [Edited by - d000hg on February 8, 2005 7:09:39 AM]
Advertisement
Maybe the SetUnhandledExceptionFilter API will do the trick for you. Take a look at the Bugslayer and UnderTheHood links in the google results.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Another possibility would be to use the Windows SEH (structured exception handling). It may be a VC++ thingy, and I don't know if it works with gcc or any other compiler.

(wait: there is something weird with this page... try here).

HTH,
Well I want to use try & catch, but Imust be able to do catch(something) that will catch the exception as CException does? MFC is just using plain c++...
If I wasn't using MFC can I detect an access violation etc using catch(something)?
You can still use try/catch but they will only catch C++ exceptions (those which are throwed). SEH can catch access violations and a lot of other errors (like divide by 0 and so on).

Reading your post, it seems you are not very clear with C++ exceptions. You don't have to use MFC to be able to use them. You don't have to define an exception object to use them. This (pseudo) code works:
try {  if (cond1) throw 1000;  if (cond2) throw "a string";  if (cond3) throw new ComplexObject(1000, "a string");} catch (int e) {}catch (const char *c) {}catch (ComplexObject *obj) {}

Regards,
I'm quite happy with c++ exception handling, but if I do
int *pointer=0;try{*pointer=12345;}catch(...){}
I believe the catch block will get called. In MFC I could do
int *pointer=0;try{*pointer=12345;}catch(CException *E){}
And I think I could then get a string telling me it was an access violation. My point is that CException is an MFC class, so while I can trap such errors without crashing the program, I don't know what has gone wrong. I basically want to know how CException works and how to duplicate it - it tells you an exception code like 0xc0000005 and a string like "Access violation"...
I think you want to look at _set_se_translator(). Be sure to compile with /EHa (asynchronous exception support) or you'll be in a world of hurt.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
try{  .....}catch(exception &e){  cout << e.what();}
That seems very useful - thanks.
Although:
try{int *p=0;*p=12345;}catch(CException *E){...}catch(exception &e){...}catch(...){...}
In this instance the last catch block is triggered, but I thought CException would catch it?

This topic is closed to new replies.

Advertisement