Jump to content
  • Advertisement
Sign in to follow this  
d000hg

Non-MFC exception handling

This topic is 4941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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,

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
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"...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

try
{
.....
}
catch(exception &e)
{
cout << e.what();
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!