Standard library / flag

flag.PanicOnError

Panics on a parsing error. The example recovers at a local boundary to demonstrate the policy. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
const PanicOnError ErrorHandling = 2

Working Example

Example Snippetgo
package main
import (  "flag"  "fmt"  "io")
func main() {  f := flag.NewFlagSet("demo", flag.PanicOnError)  f.SetOutput(io.Discard)  defer func() { fmt.Println(recover() != nil) }()  _ = f.Parse([]string{"-unknown"})}
Go Reference