Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 852 Bytes

qa-01.md

File metadata and controls

32 lines (23 loc) · 852 Bytes

Checking for errors is cumbersome

Answer 1

I have a feeling that this is one of those things you either accept or don't use Go for. I don't agree that exceptions are better, but I think it's okay if you don't agree. However, I don't think you will be able to enjoy using Go or use Go to its full potential if you can't accept this.

os.Exit() is impossible to test!

Answer 1

In other languages, I was able to easily test code that calls exit

I think the way to go about it is to only call os.Exit() from a single location, and use a return value

package main

func main() {
  if err := _main(); err != nil {
     // decide on the exit code depending on the error, if applicable
     exitCode := ....
     os.Exit(exitCode)
  }
}

func _main() error {
  if err := codeThatCausesExit(); err != nil {
     return err
}