4 ms·
It's a bunch of syntax sugar. The proposal is that instead of typing this: fn foo(b : bool) -> Result<Bar,Baz> { ... return Ok(bar);
by Tuna-Fish 4y ago
It's a bunch of syntax sugar.
The proposal is that instead of typing this:
fn foo(b : bool) -> Result<Bar,Baz> {
...
return Ok(bar);
...
return Err(baz);
}
you can type:
fn foo() -> Bar throws Baz {
...
return bar;
...
throw baz; //or yeet, in this proposal
}
and it works exactly identically as the first example. ? still works inside the function just as it normally would. I find the proposal sort of pointless, but also totally harmless, so why not.
- CryZe 4y agoThat's not all it does. It "breaks" to the nearest "try" barrier. It's basically the desugaring of the Err branch in the ? operator, that you can't currently express yourself. It's mostly relevant for try blocks. I guess you'd most commonly see this in "control flow like" macros that are similar to the ? operator, like various assertion macros that want to "yeet" an error in case the assertion fails (instead of panicking like those in std). So in a sense it actually is very similar to `throw` in traditional languages, as it can be caught inside the same function and isn't forced to `return` the error outside the function.