August 2019
Beginner to intermediate
798 pages
17h 2m
English
You can also use the panic() function on its own without any attempt to recover and this subsection will show its results using the Go code of justPanic.go, which will be presented in two parts.
The first part of justPanic.go is next:
package main
import (
"fmt"
"os"
)
As you can see, the use of panic() does not require any extra Go packages.
The second part of justPanic.go comes with the next Go code:
func main() {
if len(os.Args) == 1 {
panic("Not enough arguments!")
}
fmt.Println("Thanks for the argument(s)!")
}
If your Go program does not have at least one command-line argument, it will call the panic() function. The panic() function takes one parameter, which is the error message that you want to ...
Read now
Unlock full access