O'Reilly logo

Shared Source CLI Essentials by Ted Neward, Geoff Shilling, David Stutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling Exceptions in the PAL

The SSCLI implementation uses Win32 Structured Exception Handling (SEH) heavily, and because of this, the PAL must provide an implementation of this feature for its use.

Before launching into the details of how the PAL implements SEH portably, a quick review is in order. SEH takes the following form in Win32 code:

    _  _try {
      <guarded code>
    }
    _  _except (<filter>) {
      <exception handler>
    }
    _  _finally {
      <termination handler>
    }

The filter and its exception handler are executed if an exception occurs during the execution of the guarded code; if an exception occurs within the try block, the filter is used to determine whether the except block should be run. The termination handler is an optional piece of code that is executed whenever control moves out of the guarded section; as control moves out of the try block for any reason, the finally block is executed. Any code blocks may themselves contain try blocks,exceptblocks, orfinally blocks (or call functions that contain such blocks), and because of this, handlers may be, and often are, nested to an arbitrary depth.

The algorithm for exception handling is as follows:

  1. An exception is raised.

  2. The system looks at the hierarchy of active exception handlers and executes the filter of the handler with highest precedence. This is the exception handler most recently installed and most deeply nested.

  3. If the filter passes control by returning EXCEPTION_CONTINUE_SEARCH, execution returns to step 1 but at the next highest precedence ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required