tc39/proposal-throw-expressions

Name: proposal-throw-expressions

Owner: Ecma TC39

Description: Proposal for ECMAScript 'throw' expressions

Created: 2017-07-15 18:24:20.0

Updated: 2018-05-23 19:56:29.0

Pushed: 2018-01-23 19:52:31.0

Homepage: https://tc39.github.io/proposal-throw-expressions

Size: 168

Language: HTML

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ECMAScript throw expressions

This proposal defines new syntax to throw exceptions from within an expression context.

Status

Stage: 2
Champion: Ron Buckton (@rbuckton)

For more information see the TC39 proposal process.

Authors

Proposal

A throw expression allows you to throw exceptions in expression contexts. For example:

A throw expression does not replace a throw statement due to the difference in the precedence of their values. To maintain the precedence of the throw statement, we must add a lookahead restriction to ExpressionStatement to avoid ambiguity.

Grammar

yExpression[Yield, Await]:
hrow` UnaryExpression[?Yield, ?Await]

essionStatement[Yield, Await]:
ookahead ? {`{`, `function`, `async` [no |LineTerminator| here] `function`, `class`, `let [`, `throw`}] Expression[+In, ?Yield, ?Await] `;`

Other Notes

A throw expression can be approximated in ECMAScript using something like the following definition:

t __throw = err => { throw err; };

ia helper...
tion getEncoder1(encoding) {
nst encoder = encoding === "utf8" ? new UTF8Encoder() 
            : encoding === "utf16le" ? new UTF16Encoder(false) 
            : encoding === "utf16be" ? new UTF16Encoder(true) 
            : __throw(new Error("Unsupported encoding"));


ia arrow...
tion getEncoder2(encoding) {
nst encoder = encoding === "utf8" ? new UTF8Encoder() 
            : encoding === "utf16le" ? new UTF16Encoder(false) 
            : encoding === "utf16be" ? new UTF16Encoder(true) 
            : (() => { throw new Error("Unsupported encoding"); })();

However, this has several downsides compared to a native implementation:

Resources

TODO

The following is a high-level list of tasks to progress through each stage of the TC39 proposal process:

Stage 1 Entrance Criteria
Stage 2 Entrance Criteria
Stage 3 Entrance Criteria
Stage 4 Entrance Criteria

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.