How to handle seg faults under Windows?
Let them crash and let the Windows Error Reporting handle it - under Vista+, you should also consider registering with Restart Manager, so that you have a chance to save out the user's work and restart the application (like what Word/Excel/etc.. does)
Use SEH for early exception handling, and use SetUnhandledExceptionFilter to show a descriptive message.
If you add the /EHa
compiler argument then try {} catch(...)
will catch all exceptions for you, including SEH exceptions.
You can also use __try {} __except {}
which gives you more flexibility on what to do when an exception is caught. putting an __try {} __except {}
on your entire main()
function is somewhat equivalent to using SetUnhandeledExceptionFilter()
.
That being said, you should also use the proper terminology. "seg-fault" is a UNIX term. there are no segmentation faults on windows. On windows they are called "Access Violation exceopnts"