Search code examples
ctry-catchwdk

microsoft windows driver kit pure C try catch syntax?


In the Windows Driver Kit (WDK) there are some driver code samples written in pure C, but sprinkled with some try-catch-finally constructs. Does someone know their semantics ? Thank you microsoft for your great tools and standards compliance.

Code extract from some_file.c:

try {
    ...
    if (!NT_SUCCESS( status )) {

       leave; // ???
    }
    ...
} finally {
    ...
}

try  {
    ...
} except( EXCEPTION_EXECUTE_HANDLER ) {
    ...
}

Solution

  • The try/except handling in the WDK follows the SEH model used throughout windows. Notice that you can continue after catching an exception.

    This model predated C++, so the C++ standard is not the same as the exception model used by Win32.

    PS: C does not have exception handling, so SEH is a non-standard extension to C.

    SEH exception handling in the MSDN

    Introduction to SEH