2 ms·
unwrap panics on failure; try! is equivalent to match somefunc() { Ok(res) => res, Err(e) => return Err(e) } in Rust; or res, err := somefunc()
by PeCaN 10y ago
unwrap panics on failure; try! is equivalent to
match somefunc() {
Ok(res) => res,
Err(e) => return Err(e)
}
in Rust; or
res, err := somefunc()
if err != nil {
return err
}
in Go.
Also, while I don't really know Go, doesn't
res, _ := somefunc()
silently ignore the error instead of panicking?
- fizzbatter 10y ago> silently ignore the error instead of panicking? Correct, with the minor note that it of course depends on your usage. If `res` is a pointer, any usage of it will panic because you ignored the err
- __s 10y agoWhich means if you don't use that pointer for awhile you're going to have to do some backtracking to that ignored error
- giovannibajo1 10y agoWhich is why nobody writes that in production code; it's only used in examples and maybe tests