News for hackers. Stuff that matters.
Re:From Node.js to Go by Jweb_Guru on Friday January 30, 2015 @01:08PM (#8973344)
Idiomatic Rust uses try!. It is a less verbose version of the most common pattern of error handling in Go. You have not programmed very much Rust and are not yet familiar with its idioms, but that is by far the most common and avoids all the problems you just described.
Re:From Node.js to Go by Animats on Saturday January 31, 2015 @12:46AM (#8976019)
"try!" is close to something one might call "cruft". It tests a function for an error value, and if it gets one, it returns from the containing function. "try!()" is written like a function call, but it doesn't work like one - it can execute a return statement. That's outside the normal semantics of the language. This is the only macro in the standard macros with such semantics. Fortunately. This is a capability which needs to be used with extreme restraint. Writing a macro "try_except_finally!(maincode, exceptioncode, cleanupcode)" would probably be a bad idea.

There was at one time a fad for extending C with macros like that. Fortunately for program readability, it didn't last.

Re:From Node.js to Go by Manishearth on Sunday February 01, 2015 @09:11PM (#8982451)
`throw` in Java's exception handling also prematurely exits a function. So?

While `try!()` is a macro and not a core language feature, most of the macros in the standard library can be treated as such. So a Rust programmer will know that `try!()` can return, just like a Java programmer knows that `throw` returns early.

Besides, macros are syntactically distinguishable in Rust. When you see that exclamation mark, you have to rememeber that it's a macro and might be doing arbitrary compile time things along with arbitrary token tree expansion.

Re:From Node.js to Go by Jweb_Guru on Saturday January 31, 2015 @01:26PM (#8977497)
Except that in Rust, all macros are syntactically distinguished from non-macros (as well as hygienic, unlike C macros), and try! is extremely common (so the claim that people won't know what it does is questionable). I agree that macros like this should be carefully considered, but I think experience has already shown us that try! is perfectly fine.