|
|
|
|
|
by bayindirh
2 days ago
|
|
Here's an example file: https://files.bayindirh.io/misc/error_example.go I have commented inside the code, but to recap here: - If you don't declare err variable, the code won't compile.
- If you don't use err variable, the code won't compile again.
So, you need to both declare and use the err variable to be able to compile the code. So you can't forget. Your code will not compile.The only way to "forget" is to declare err as "_", which I call IDGAF placeholder, and this is a deliberate choice to ignore that variable. So you willingly and knowingly ignore the error variable. Otherwise Go won't give you Go ahead. Seriously, try to compile the example I have given. It's fresh, so hold with mittens. |
|
``` a, err := f() b, err := g() if err != nil {} c:=a+b ```
The language will happily build and run, even though it should prevent to let you shoot in the foot.