panic

A Go run-time failure that stops normal execution, runs deferred functions and, unless recovered, crashes the program with a stack trace.

In more detail

Panics happen on programming mistakes such as an index out of range, a nil pointer dereference or writing to a nil map, and you can trigger one with panic(). They signal a broken invariant, not an expected failure; return an error for things like a missing file. A panic unwinds only the goroutine it happened in, but an unrecovered panic ends the whole program.

Example

panic("bad invariant")

Related terms

Taught in

References