Standard library / runtime/debug

debug.SetPanicOnFault()

Changes unexpected memory-fault handling for the current goroutine and returns the prior setting. Does not make unsafe memory access safe; no fault is triggered here. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func SetPanicOnFault(enabled bool) bool

Parameters & Attributes

NameTypeDescription
enabledboolWhether unexpected faults in this goroutine should panic instead of crashing.

Return Value

bool

Previous setting for the calling goroutine.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime/debug")
func main() {  old := debug.SetPanicOnFault(true)  defer debug.SetPanicOnFault(old)  fmt.Println(debug.SetPanicOnFault(old))}
Go Reference