currently i am catching it using __try __except
but this has few limitations and i want to catch those exceptions in C++
catch handler
thanks in advance
You can, but it requires some preparations. By default C++
try-catch block won't handle SEH exceptions.
> currently i am catching it using __try __except
> but this has few limitations and i want to catch those
> exceptions in C++ catch handler
Read this FAQ, it explains the difference between C++ nad SEH
exceptions and how to handle both types correctly:
"A Visual C++ Exception FAQ"
http://members.cox.net/doug_web/eh.htm
HTH
Alex
but i am still confused about the best way to catch the SE in C++ To be
more specific @ what i want
1. I Agree that Structured Exceptions represent bugs in the program. But
the code is very huge and i hardly have time to run through all Line of code
and check for programming bug :) ..
2. The Tool crashes in live environment and causes panic @ client site so
as a short term fix what i want to do is catch those SE in the code and
handle those exception set of documents move them in separate directory and
process next document this way the tool will not stop even though there is
Win32 SE
i have written __try and __except block in main function but i want it
closer to a processing function so that the tool wont stop after exception
and i can restart the function ..
but when i tried putting __try __Except around the function compiler gives
me error
C2712: Cannot use __try in functions that require object unwinding
any idea @ ideal solution in this case ?
C doesn't have exceptions. What you probably mean is win32 SEH, which is
available as a compiler extension using __try/__except.
> but i am still confused about the best way to catch the SE in C++ To be
> more specific @ what i want
>
> 1. I Agree that Structured Exceptions represent bugs in the program. But
> the code is very huge and i hardly have time to run through all Line of
> code and check for programming bug :) ..
SEs don't necessarily represent bugs. Also, ignoring them isn't likely to
make your program run any better.
> 2. The Tool crashes in live environment and causes panic @ client site so
> as a short term fix what i want to do is catch those SE in the code and
> handle those exception set of documents move them in separate directory
> and process next document this way the tool will not stop even though
> there is Win32 SE
>
> i have written __try and __except block in main function but i want it
> closer to a processing function so that the tool wont stop after exception
> and i can restart the function ..
What you could do is
try {
...
} catch(std::exception const& e) {
log("exception: %1", e.what());
...
} catch(...) {
log("unknown exception);
...
}
In any case, there is no guarantee that you can recover from what the SE is
signalling. It could be that it is thrown due to a corrupted stack or
similar things. Just pretending it didn't happen and continuing won't get
you far.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Then you should build your program with /EHa compiler switch
(asynchronous model), it will allow you to catch SEH exceptions in
catch(...) clause. Also, you may establish translation for SEH
exceptions to C++ exceptions with `_set_se_translator' call. See
short example here:
"Exception Handling Differences"
http://msdn.microsoft.com/en-us/library/de5awhsw.aspx
HTH
Alex
basically i am interested to catch buffer overflow , NULL pointer referencing
and print stack of the line which caused this as a part exception handling
routine
this will help me to trace the bug .
Oh, yes, you will have to tell the compiler that you want SEs in C++ catch
blocks.
> basically i am interested to catch buffer overflow , NULL pointer
> referencing and print stack of the line which caused this as a part
> exception handling routine this will help me to trace the bug .
Oh, getting out that information is a bit more tricky. I don't have a link
here, but search for "minidump", which should allow you to preserve some
information.
good luck!
..
Be more specific. What do you mean by "crash windows"? Post here
small example that demonstrates the problem.
Alex
Instead of catching the structured exception directly I convert the
structured exception into a C++ exception using _set_se_translator then
catch the C++ exception. This is described in the MSDN article titled
"Handling Exceptions, Part 17". However I just searched msdn.microsoft.com
and can not find this article even though it is in my local MSDN library.
Perhaps others know how to search msdn.microsoft.com more effectively.
John
Try with "SetUnhandledExceptionFilter".
Regards,
John.
"sachin" <sac...@discussions.microsoft.com> wrote in message
news:F6C7F5F3-8C5D-4655...@microsoft.com...
John i will try SetUnhandledExceptionFilter thanks