
throw (C# Reference)
The throw statement is used to signal the occurrence of an anomalous situation (exception) during the program execution.
Remarks
The thrown exception is an object whose class is derived from System.Exception, for example:
Usually the throw statement is used with try-catch or try-finally statements. When an exception is thrown, the program looks for the catch statement that handles this exception.
You can also rethrow a caught exception using the throw statement. For more information and examples, see try-catch and Throwing Exceptions.
Example
This example demonstrates how to throw an exception using the throw statement.
C# Language Specification
For more information, see the following sections in the C# Language Specification:
5.3.3.11 Throw statements
8.9.5 The throw statement
See Also
Tasks
How to: Explicitly Throw ExceptionsReference
The try, catch, and throw StatementsC# Keywords
Exception Handling Statements (C# Reference)
