Proposal: A built-in Go error check function, try
1–10 of 127 posts
Re: Proposal: A built-in Go error check function, try
#2From experience, those work pretty well. That approach eliminates a lot of the boilerplate bookkeeping code, while still making it explicitly obvious to the reader that a given function call can fail.
This seems nice, and I would definitely use it.
[1] https://github.com/protocolbuffers/protobuf/blob/master/src/...
Re: Proposal: A built-in Go error check function, try
#3Re: Proposal: A built-in Go error check function, try
#4 f, err := os.Open(filename)
if err != nil {
return …, err // zero values for other results, if any
}
can be simplified to f := try(os.Open(filename))
This makes a lot of sense, but I'm of two minds. On one hand, it makes things much cleaner. On the other hand, it might be a first step onto a slippery slope that ends with exceptions.A lot of others chiming in with different ideas on the original ticket: https://github.com/golang/go/issues/32437
Re: Proposal: A built-in Go error check function, try
#5Should `try` wraps the error and adds something more useful for debugging purpose? (the line number probably?)
Re: Proposal: A built-in Go error check function, try
#6So basically they're proposing: f, err := os.Open(filename) if err != nil { return …, err // zero values for other results, if any } can be simplified to f := try(os.Open(filename)) This makes a lot of sense, but I'm of two minds. On one hand, it makes things much cleaner. On the other hand, it might be a first step onto a slippery slope that ends with exceptions. A lot of others chiming in with different ideas on th…
Interestingly, this means that while pervasive use of "if err != nil { return err }" is technically very similar to exceptions when used everywhere, it can still have a different semantic meaning to a human reading the source.
Re: Proposal: A built-in Go error check function, try
#7Great functionality though. I'd be very happy to see this included no matter what it's named.
EDIT: This is answered in the FAQ section after I read further. Apparently it's because "try" is already a keyword. I still don't like it, but I get it.
Re: Proposal: A built-in Go error check function, try
#8It's the try! macro from Rust! Obviously I'm a big fan of this style of error handling, and I'm happy to see it proposed for Go.
Re: Proposal: A built-in Go error check function, try
#9Go is awesome for its simplicity. Errors should not be abstracted out of handling convenience. Errors are just values either eliminate the need for the error or handle it like you would any other value.
Stop trying to make go work like every other language.
Re: Proposal: A built-in Go error check function, try
#10Here is my proposal: add restarts [0] as a complement to manual propagation.
[0] https://github.com/codr7/g-fu/blob/master/v1/doc/typical_res...