3 ms·
But you have to write the `catch` (or a `throws`). That's the point. Now if you choose to handle this stupidly, that's entirely your fault, but at least the co
by incepted 11y ago
But you have to write the `catch` (or a `throws`). That's the point.
Now if you choose to handle this stupidly, that's entirely your fault, but at least the compiler did its jobs by forcing you to think about the error case.
In Go, the compiler doesn't enforce anything.
- ngrilly 11y agoHow many lines of Go have you written before writing this? In Go, as in Java with checked exceptions, the compiler forces the programmer to handle the error. Using _ in Go is not idiomatic. It's the exact equivalent of using a try/catch block with nothing in the catch block in Java.
- Karunamon 11y agoOr not checking for the exception at all. Certain classes of errors can and should be allowed to pass up the call stack and cause your program to die (something strange that I wasn't expecting and don't know how to handle happened, and now I'm in a bad state - safer to exit)
- pcwalton 11y agoIf you call a function that returns nothing but an error, Go does not force you to acknowledge the error's existence and will silently allow you to drop it.