Chapter 11 Quick Reference


To

Do this

Generate an exception.

Use the throw keyword, using a pointer to a managed type as the argument. For example:

throw new SomeException();

Catch an exception.

Use the try and catch construct, surrounding the code that might fail with a try block, followed by one or more catch blocks. For example:

try { // code that might fail } catch(SomeException* pce) { // handle the exception }

Catch more than one exception.

Chain catch blocks together. For example:

catch(SomeException* pce) { // handle the exception } catch(SomeOtherException* pce) { // handle the exception }

Catch a family of
exceptions.

Use the base class of the exceptions you want to catch in the catch block; for example, ArithmeticException will catch DivideByZeroException and several others.

Catch every exception.

Use a catch block that takes Exception* as a parameter, which will catch every type that is derived from Exception.

Handle exceptions at more than one point in a program.

Use throw to rethrow exceptions from one catch block to another.

Create your own
exceptions.

Derive from the Exception class, adding your own members.




Microsoft Visual C++  .NET(c) Step by Step
Microsoft Visual C++ .NET(c) Step by Step
ISBN: 735615675
EAN: N/A
Year: 2003
Pages: 208

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net