Sign in to follow this  
Wavesonics

C++ Automatic crash reports

Recommended Posts

Wavesonics    330
So I was looking at some one's C# code, and C#, admittedly a much more structured language where every problem produces an exception before crashing the program, provides functionality for attaching a handler for C# to call when it encounters an unhanded exception *anywhere* in your program. So using that this handler, he had it dump to disk and send the file to an FTP server. Then the server emailed him of the new crash report. I mean that is just fantastic, you know about every crash every time. So I am of course curious if anyone has come up with any interesting way of doing this in C++. Obvious problems being, C++ doesn't produce exceptions for crash conditions that you didn't specify, and doesn't provide any sort of functionality for staying alive a little longer to do something like send a crash report. Still, anyone come up with anything? Maybe another process which monitors it or something? Might be too slow for games, but for other software it would be nice.

Share this post


Link to post
Share on other sites
Sneftel    1788
Quote:
Original post by Wavesonics
I'm pretty partial to writing cross platform code, but maybe in this case thats not possible

Not possible here, unfortunately. The history of C and C++ is such that crash handling is considered the exclusive domain of the OS.

Share this post


Link to post
Share on other sites
swiftcoder    18432
Quote:
Original post by Sneftel
Quote:
Original post by Wavesonics
I'm pretty partial to writing cross platform code, but maybe in this case thats not possible

Not possible here, unfortunately. The history of C and C++ is such that crash handling is considered the exclusive domain of the OS.


Would wrapping your entire main function with a catch (...) clause do the trick? I am assuming not, since SEGFAULT and such are not C++ exceptions.

However, on *nix machines you get a core dump on a crash, so a monitor process could email that.

Share this post


Link to post
Share on other sites
SiCrane    11839
Not really. Any crash handler that exists inside the process that crashed is subject to some sort of destructive interference from the crash itself. For example a catch (...) block compiled with /EHa in MSVC will catch pretty much every SEH exception that the system can raise. However, it may not be in a position to do anything with that information. What if the SEH exception was due to a stack overflow? You'd want to generate a stack walk to display what function went bonkers, but in order to do that you need to perform the stack walk while the full contents of the stack are there, but that means you don't have the stack space necessary to call stack walking functions.

Share this post


Link to post
Share on other sites
HappyCoder    5052
Would it work to write a crash handling class that attempts to implement crash handling for any operating system. Then you use #ifdef statements to let the complier select the operating system's functions to catch exceptions.


void CrashHandler::Initialize()
{
#ifdef WINDOWS
// windows code
#endif
#ifdef LINUX
// linux code
#endif
}



Not sure if you would actually be checking for 'WINDOWS' or 'LINUX' specifically but hopefully you get the idea.

Share this post


Link to post
Share on other sites
Wavesonics    330
Well that would work, but like a lot of them are saying, the big problem here is that so many things that could crash the program would not produce exceptions in C++.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this