Here are some examples of suchįunctions: set_terminate(), _set_invalid_parameter_handler(), _set_purecall_handler(). I browsed MSDN some more and found many other CRT-provided functions that could be used to handle CRT errors. Watson's window still appears instead of the CrashRpt window. Of exceptions in my application are somehow left unhandled and Dr. Watson) windowīrowsing the MSDN gave me the SetUnhandledExceptionFilter() function that I used to handle access violations. The error (such as crash minidump, error logs, desktop screenshots), and offers the user to send an error report over the Internet (figure 1).įigure 2 - Windows Error Reporting (Dr. The CrashRpt library handles exceptions occurring in your application, collects technical information about Some time ago I needed a way for intercepting exceptions for one of my Open-Source projects, CrashRpt - A crash reporting
The demo can raise and catch different types of exceptionsĪnd generate a crash minidump file allowing to see the line of the code where exception occurred. The exception handling mechanisms and effectively use exception handling in your C++ applications.Ī small console demo application ExceptionHandler is attached to the article. This article is aimed to help you better understand The variety of error types, differences of handling exceptions in multi-threaded programs, and dependence of exception handling on CRT linkage requiresĪ lot of work to handle exactly all exceptions that your application is allowed to handle. Exception handling techniques strongly depend on the CRT linkage type.
So you have to install exception handlers in each thread.Įach module (EXE or DLL) in your application is linked to CRT libraries (either statically or dynamically). Some exception handlers work for an entire process, but some workįor the current thread only. If your application has several execution threads, things may be even more complicated. Intercept an exception and do some error recovery actions. Each error type requires installing an exception handler function that would This article describes the standard techniques of handling exceptions and errors in Visual C++ programs running in Windows.Īn exception (or a critical error, or crash) typically means your program stops working normally and needs to stop its execution.įor example, an exception may occur because of your program accessing an invalid memory address (such as NULL pointer), memory bufferĬan't be allocated (out of memory), the C run-time libraries (CRT) detect an error and request program termination, and so on.Ī C++ program may handle several types of exceptions: SEH exceptions produced through the Operating System's structured exception handling mechanism,ĬRT errors produced by the C run-time libraries, and finally, signals.