Some doubt in Exception Handling

Rohan Pande 445 Reputation points
2024-03-29T11:51:46.94+00:00

I am trying to learn about the exception handling provided by Windows operating system. Now there are two different types of exception handling:

  1. One we probably know where we know that this call could fail -- we could use Structured Exception Handling which involves using of try,except, finally blocks.
  2. Other is we could register the exception handler So, I got two APIs one is AddVectoredExceptionHandler and other one is SetUnhandledExceptionFilter. I checked they are pointing both to the EXCEPTION_POINTERS structure.

For the first use case I am clear of using try blocks whenever necessary, but I am confused for the second type as there are two different APIs so when to use which one?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,653 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,786 Reputation points Microsoft Vendor
    2024-04-01T03:36:20.3033333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    According to the Doc:Vectored Exception Handling

    Vectored handlers are not frame-based, therefore, you can add a handler that will be called regardless of where you are in a call frame.

    According to the Doc:UnhandledExceptionFilter

    This function can be called only from within the filter expression of an exception handler.

    As far as I'm concerned, it is frame-based.

    According to the link: https://stackoverflow.com/a/54879453/11872808

    VEH handlers added by AddVectoredExceptionHandler will handle exceptions before they reach frame-based handlers.

    Filter set by SetUnhandledExceptionFilter will handle exceptions after frame-based handlers failed.

    And you could refer to the thread: Is AddVectoredExceptionHandler a replacement for SetUnhandledExceptionFilter?

    Vectored Exception Handling is useful as a diagnostic tool.

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.