Export (0) Print
Expand All

BoxedValue Sample: Demonstrates Throwing and Catching an Instance of a Value Class

Visual Studio .NET 2003

The BoxedValue sample illustrates the throwing and catching of an instance of a value class. This sample demonstrates the need for boxing a value class instance before it is thrown and catching the boxed value as an unboxed value type.

Note   An unboxed value type is a pointer to the unboxed copy of the value type instance.

For more information on boxing, see __box.

Building and Running the Sample

To build and run BoxedValue using Visual Studio

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

The following output is displayed in the console window:

Caught a boxed value type:1


This sample demonstrates the following keywords:

try, catch, __box, __value

See Also

Managed Extensions for C++ Samples

© 2015 Microsoft