O'Reilly logo

Special Edition Using C# by NIIT

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

Exception-Handling Statements

The following section describes the exception-handling statements in C#.

The throw Statement

The throw statement consists of the throw keyword followed by the expression for which an exception is thrown. The exception is thrown when the expression is evaluated. This exception must be an instance of the System.Exception class or any type derived from the same. The following example declares a throw statement that throws an

ArrayTypeMismatchException: 

throw(new ArrayTypeMismatchException());

The expression following the throw keyword is optional. A throw statement that does not have an expression can only be specified in a catch block. The catch block then rethrows the same exception and an appropriate catch block ...

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