There are two types of exceptions: hardware and software. A event that hardware exception is an causes the processor to alter its normal flow of execution inside a process's instructions. We have been primarily looking at hardware exceptions such as divide-by-zero and access violations. Hardware exceptions tend to be highly processor-dependent.
Software exceptions are explicitly generated by software. You can explicitly generate an exception using the Windows API RaiseException. This has the following format:
VOID RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD cArguments, LPWORD lpArguments);
This is an easy way to have application-defined exceptions. But one should take care not to swallow exceptions. A swallowed exception occurs when one handles an exception that is meant for another handler. You should never have a filter that simply sets EXCEPTION_EXECUTE_HANDLER without checking whether the exception code is what you're expecting.
The first parameter dwExceptionCode sets the user-defined exception code. The second parameter, dwExceptionFlags, must be 0 or 1 (EXCEPTION_NONCONTINUABLE_EXCEPTION). A 0 indicates that you can recover from this exception while a 1 indicates that you cannot. If EXCEPTION_NONCONTINUABLE_EXCEPTION is set, then it is incorrect for a filter to evaluate to EXCEPTION_CONTINUE_EXECUTION. If such a filter is encountered, the system will generate a new exception called EXCEPTION_NONCONTINUABLE_EXCEPTION.
The third and fourth parameters allow you to pass application-defined data as arguments. If you don't need them, set them to NULL. Otherwise, use cArguments to indicate the number of elements in the DWORD array pointed to by the lpArguments parameter. This parameter cannot exceed EXCEPTION_MAXIMUM_PARAMETERS which is also defined in <winnt.h>, as 15.
If you decide to generate your own application-defined exceptions, follow the standard set in <winerror.h> for the exception code you choose.
If you don't want to define any application-defined exceptions, just use RaiseException to emulate one of the hardware exceptions, such as:
RaiseException(EXCEPTION_ACCESS_VIOLATION, 0,0,0);
![]()
Structured Exception Handling
Exception Handler - Global
Unwind
Exception Handler - Exception
Information
