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 259 views
1 answer 226 views
1 answer 166 views
1 answer 177 views
2 answers 244 views
1 answer 118 views
118 views asked May 19, 2025 by avibootz
...