Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

Chapter 15 Statements

1If the return statement is enclosed by one or more try blocks with associated finally blocks,

2control is initially transferred to the finally block of the innermost try statement. When and if

3control reaches the end point of a finally block, control is transferred to the finally block of the

4next enclosing try statement. This process is repeated until the finally blocks of all enclosing try

5statements have been executed.

6Control is returned to the caller of the containing function member.

7Because a return statement unconditionally transfers control elsewhere, the end point of a return

8statement is never reachable.

915.9.5 The throw statement

10The throw statement throws an exception.

11throw-statement:

12throw expressionopt ;

13A throw statement with an expression throws the value produced by evaluating the expression. The

14expression shall denote a value of the class type System.Exception or of a class type that derives from

15System.Exception. If evaluation of the expression produces null, a

16System.NullReferenceException is thrown instead.

17The throw statement can be used with an expression whose type is given by a type parameter (§26.1.1) only

18if that type parameter has System.Exception (or a subclass thereof) as its effective base class (§26.7).

19A throw statement with no expression can be used only in a catch block, in which case, that statement re-

20throws the exception that is currently being handled by that catch block.

21Because a throw statement unconditionally transfers control elsewhere, the end point of a throw statement

22is never reachable.

23When an exception is thrown, control is transferred to the first catch clause in an enclosing try statement

24that can handle the exception. The process that takes place from the point of the exception being thrown to

25the point of transferring control to a suitable exception handler is known as exception propagation.

26Propagation of an exception consists of repeatedly evaluating the following steps until a catch clause that

27matches the exception is found. In this description, the throw point is initially the location at which the

28exception is thrown.

29In the current function member, each try statement that encloses the throw point is examined. For each

30statement S, starting with the innermost try statement and ending with the outermost try statement, the

31following steps are evaluated:

32o If the try block of S encloses the throw point and if S has one or more catch clauses, the catch

33clauses are examined in order of appearance to locate a suitable handler for the exception. The first

34catch clause that specifies the exception type or a base type of the exception type is considered a

35match. A general catch (§15.10) clause is considered a match for any exception type. If a matching

36catch clause is located, the exception propagation is completed by transferring control to the block

37of that catch clause.

38o Otherwise, if the try block or a catch block of S encloses the throw point and if S has a finally

39block, control is transferred to the finally block. If the finally block throws another exception,

40processing of the current exception is terminated. Otherwise, when control reaches the end point of

41the finally block, processing of the current exception is continued.

42If an exception handler was not located in the current function member invocation, the function member

43invocation is terminated. The steps above are then repeated for the caller of the function member with a

44throw point corresponding to the statement from which the function member was invoked.

45If the exception processing terminates all function member invocations in the current thread, indicating

46that the thread has no handler for the exception, then the thread is itself terminated. The impact of such

47termination is implementation-defined.

233

Соседние файлы в предмете Электротехника