Allow `try…catch` blocks to return a value.

# Bucaran (4 years ago)

Allow try…catch blocks to return a value.

Sometimes I wrap a try…catch in a function and return a value based in whether there was an error or not.

It would be useful if you could use return inside a try…catch block to accomplish the same.

 let stuff = try {
   return ...
 } catch (e) { return … ? … : ... }
# Gary Guo (4 years ago)

This is not possible as it contracts with existing semantics. Wrap it with a function instead.

# Andreas Rossberg (4 years ago)

Do-expressions will solve this:

 let stuff = do { try {
   f()
 } catch (e) { 0 } }

The inflation of braces is somewhat ugly there, and we might want to allow dropping some of them.

# Michał Wadas (4 years ago)
let stuff = ()=>{ try {
   return f();
} catch(e){ return f; } }();

14 chars more.

# Bucaran (4 years ago)

Exactly, but the reason I proposed this is because the method your are describing was not satisfactory enough / I found it inconvenient.