Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification 15 Statements 15.9 Jump statements 15.9.5 The throw statement
Paragraph 11 The throw statement throws an exception. throw-statement : throw expressionopt ;
Paragraph 21 A throw statement with an expression throws the value produced by evaluating the expression. 2 The expression must denote a value of the class type System.Exception or of a class type that derives from System.Exception. 3 If evaluation of the expression produces null, a System.NullReferenceException is thrown instead.
Paragraph 31 A throw statement with no expression can be used only in a catch block, in which case, that statement re-throws the exception that is currently being handled by that catch block.
Paragraph 41 Because a throw statement unconditionally transfers control elsewhere, the end point of a throw statement is never reachable.
Paragraph 51 When an exception is thrown, control is transferred to the first catch clause in an enclosing try statement that can handle the exception. 2 The process that takes place from the point of the exception being thrown to the point of transferring control to a suitable exception handler is known as exception propagation. 3 Propagation of an exception consists of repeatedly evaluating the following steps until a catch clause that matches the exception is found. 4 In this description, the throw point is initially the location at which the exception is thrown.
- 5 In the current function member, each try statement that encloses the throw point is examined. 6 For each statement S, starting with the innermost try statement and ending with the outermost try statement, the following steps are evaluated:
- 7 If the try block of S encloses the throw point and if S has one or more catch clauses, the catch clauses are examined in order of appearance to locate a suitable handler for the exception. 8 The first catch clause that specifies the exception type or a base type of the exception type is considered a match. 9 A general catch (§15.10) clause is considered a match for any exception type. 10 If a matching catch clause is located, the exception propagation is completed by transferring control to the block of that catch clause.
- 11 Otherwise, if the try block or a catch block of S encloses the throw point and if S has a finally block, control is transferred to the finally block. 12 If the finally block throws another exception, processing of the current exception is terminated. 13 Otherwise, when control reaches the end point of the finally block, processing of the current exception is continued.
- 14 If an exception handler was not located in the current function member invocation, the function member invocation is terminated. 15 The steps above are then repeated for the caller of the function member with a throw point corresponding to the statement from which the function member was invoked.
- 16 If the exception processing terminates all function member invocations in the current thread, indicating that the thread has no handler for the exception, then the thread is itself terminated. 17 The impact of such termination is implementation-defined.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|