How to exit with error code from a program in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println("Go")

	os.Exit(1) // Catchall for general errors

	fmt.Println("After exit...")
}



/*
run:

Go

Program exited: status 1.

*/

 



answered Aug 7, 2020 by avibootz

Related questions

2 answers 261 views
1 answer 231 views
1 answer 173 views
1 answer 181 views
2 answers 266 views
1 answer 126 views
126 views asked May 19, 2025 by avibootz
...