O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

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

VC++ Exceptions

Handling managed exceptions in VC++ is basically the same as C#. VC++ using managed extensions exposes some features of exceptions that are not available in C#. Those differences will be illustrated later. Listing 15.12 shows how to define and use a custom exception class. The full source for this sample can be found in C++Exceptions\BasicExceptions.

Listing 15.12. Basic Managed VC++ Exceptions
__gc class MyException : public System::ApplicationException
{
public:
    MyException() : System::ApplicationException()
    {
    }
    MyException(System::String __gc *msg) : System::ApplicationException(msg)
    {
    }
} ;
void ThrowMyException()
{
    throw new MyException(new System::String("This exception is thrown from
 ThrowMyException")); } int wmain(void) ...

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