News for hackers. Stuff that matters.
Re:TypeScript Is Surprisingly OK for Compilers by xscott on Friday August 18, 2023 @04:12AM (#37172664)
What does a try expression like this do? Returns null/undefined on a throw?

I suspect you could do something like:

    const c = attempt(() => ... );
where attempt invokes the lambda, catches any exceptions, and does what you want
Re:TypeScript Is Surprisingly OK for Compilers by lmm on Friday August 18, 2023 @04:33AM (#37172811)
> What does a try expression like this do? Returns null/undefined on a throw?

If an exception is caught, the expression evaluates to what the catch block evaluates to. (Similar to having if/else be an expression). Of course if the exception isn't caught then it propagates so the expression doesn't take a value.

Re:TypeScript Is Surprisingly OK for Compilers by afandian on Friday August 18, 2023 @10:15AM (#37175915)
Kotlin has this feature (`try` and `if` are expressions not statements), and a good model for return values. https://kotlinlang.org/docs/exceptions.html#exception-classe...