This issue is primarily for condensing technical ideas into practical ones. If you want to discuss something you see here, feel free to open a new issue.
The try operator
/**
* ( try something())
* (<operator> <expression>)
*/
operator try(expression) {
try {
return TryResult.ok(exec(expression));
} catch (inner) {
return TryResult.error(inner);
}
}
does this
const a = try something()
const [[ok, err, val]] = [try something()]
const [ok, err, val] = try something()
files.map(file => try JSON.parse(file))
yield try something()
try yield something()
try await something()
try a instanceof b
(try a) instanceof TryResult
const a = try try try try try try 1
This issue is primarily for condensing technical ideas into practical ones. If you want to discuss something you see here, feel free to open a new issue.
The
tryoperatorlike any operator,
like the
yieldoperator,like the
tryblock,awaitandyieldkeywords.To maintain equivalence,
try {}: It must catch any exception thrown by a specific section of code.catch (e) {}: It must allow different code to execute if an exception was caught and provide a reference to the exception thrown.finally {}: It must allow code to execute regardless of whether or not an exception was caught.this gives us two more invariants
Result, it must still wrap it in a newResultregardless. Otherwise, the user could not distinguish between returningResult(false)and actually throwing, or between throwingResult(true)and actually returning.does this