> `if err != nil` is a convention. It's not a checked error.
It's... obviously both.
Re:Warming up to Go
by jacques_chester on Saturday September 12, 2015 @12:43PM
(#10208531)
Sorry, typo. "Checked exception", meaning that the compiler enforces error handling and that you can look a method signature and learn what kind of exceptions the method can throw without needing to read its internals.
Re:Warming up to Go
by superuser2 on Saturday September 12, 2015 @02:53PM
(#10208912)
'err' is sitting there in the return value and the compiler will force you to either use it or explicitly steamroll it. The difference between C bounds checking and Go error checking is that you can't forget to check an error in Go.
I guess everyone is remembering to check the return values of fmt.Println() then huh?
And runtime exceptions? What about them?
Re:Warming up to Go
by jacques_chester on Saturday September 12, 2015 @12:46PM
(#10208538)
They leave you in about the same position as a programmer in a dynamic language.
The advantage of runtime exceptions over Go is that I will get a fatal crash and a stacktrace. I don't have computation proceeding in an undefined, difficult-to-debug way because I forgot to do `err != nil` somewhere (particularly for functions that only return err).
Or someone will catch it and discard the result which is often often what occurs. For example, with java throw an exception in an executor task (an assertion failure for example). What do you think occurs?
Re:Warming up to Go
by jacques_chester on Sunday September 13, 2015 @07:34AM
(#10211030)
Which happens in Go too. I've seen a lot of code that happily sails past functions which only return err, meaning the compiler never pipes up.
Don't get me wrong, though. I become grumpy when I see empty catch clauses. Or a logger figleaf.
Does it?
`if err != nil` is a convention. It's not a checked error. It's like saying "C has explicit array bounds checking", if the convention was to check it by hand.
For all the hate Java gets, when I have a checked exception, I know what it is going to be. I don't need to dig around in sourcecode trying to work out if I should care or not. I don't need to check which of the three Golang error-distinction idioms (package-variable errors, error subtypes, plain-old-errors-with-magical-strings) is in play.
As you can guess, I don't like Go.