This documentation is archived and is not being maintained.

SEHCleanup Sample: Demonstrates Writing Cleanup Code Using __finally for a Try-Catch Block Involving Common Language Runtime Exceptions

Visual Studio .NET 2003

The SEHCleanup sample illustrates throwing an instance of System::Exception, catching it in a catch handler, and then doing cleanup using a __finally clause before passing the control to the next statement. The sample also shows how to catch the common language runtime exception and rethrow it, and the use of nested try-catch statements.

Building and Running the Sample

To build and run SEHCleanup using Visual Studio

  1. In the Visual Studio IDE, load the solution file SEHCleanup.sln.
  2. In Solution Explorer, right-click the SEHCleanup solution.
  3. On the shortcut menu, click Build.
  4. On the Debug menu, click Start.

The following output is displayed in the console window:

Inner Catch
Inner Finally
Outer Catch
Outer Finally

Classes and Keywords

This sample demonstrates the following class:


This sample demonstrates the following keywords:

try, catch, throw, __finally

See Also

Managed Extensions for C++ Samples