14.15 The try
Statement
Syntax
The try
statement encloses a block of code in which an exceptional condition can occur, such as a runtime error or a throw
statement. The catch
clause provides the exception-handling code. When a catch clause catches an exception, its
14.15.1 Static Semantics: Early Errors
-
It is a Syntax Error if
BoundNames ofCatchParameter contains any duplicate elements. -
It is a Syntax Error if any element of the
BoundNames ofCatchParameter also occurs in theLexicallyDeclaredNames ofBlock . -
It is a Syntax Error if any element of the
BoundNames ofCatchParameter also occurs in theVarDeclaredNames ofBlock .
An alternative
14.15.2 Runtime Semantics: CatchClauseEvaluation
The
- Let oldEnv be the
running execution context 's LexicalEnvironment. - Let catchEnv be
NewDeclarativeEnvironment (oldEnv). - For each element argName of the
BoundNames ofCatchParameter , do- Perform ! catchEnv.CreateMutableBinding(argName,
false ).
- Perform ! catchEnv.CreateMutableBinding(argName,
- Set the
running execution context 's LexicalEnvironment to catchEnv. - Let status be
Completion (BindingInitialization ofCatchParameter with arguments thrownValue and catchEnv). - If status is an
abrupt completion , then- Set the
running execution context 's LexicalEnvironment to oldEnv. - Return ? status.
- Set the
- Let B be
Completion (Evaluation ofBlock ). - Set the
running execution context 's LexicalEnvironment to oldEnv. - Return ? B.
- Return ?
Evaluation ofBlock .
No matter how control leaves the
14.15.3 Runtime Semantics: Evaluation
- Let B be
Completion (Evaluation ofBlock ). - If B is a
throw completion , let C beCompletion (CatchClauseEvaluation ofCatch with argument B.[[Value]]). - Else, let C be B.
- Return ?
UpdateEmpty (C,undefined ).
- Let B be
Completion (Evaluation ofBlock ). - Let F be
Completion (Evaluation ofFinally ). - If F is a
normal completion , set F to B. - Return ?
UpdateEmpty (F,undefined ).
- Let B be
Completion (Evaluation ofBlock ). - If B is a
throw completion , let C beCompletion (CatchClauseEvaluation ofCatch with argument B.[[Value]]). - Else, let C be B.
- Let F be
Completion (Evaluation ofFinally ). - If F is a
normal completion , set F to C. - Return ?
UpdateEmpty (F,undefined ).