Standard library / runtime

runtime.PanicNilError

Runtime error representing panic(nil) under Go 1.21+ default semantics. GODEBUG=panicnil=1 changes this behavior. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type PanicNilError struct {}

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  func() {    defer func() { r, ok := recover().(*runtime.PanicNilError); fmt.Println(ok && r != nil && r.Error() != "") }()    panic(nil)  }()}
Go Reference