Essential Go  Edit on GitHub      File Issue

Panic and recover

This chapter assumes knowledge of defer.

In Go panic and recover are technically similar to exception handling in languages like C#, Java or Python.

panic is equivalent of throw or raise and recover fills the role of catch.

However, while those other languages often use exception handling for flow control, as a way to propagate errors up the call chain, using panic in Go is highly discouraged.

It should only be used in truly exceptional cases.

For ordinary error handling, read chapter on error handling.

  ↑ ↓ to navigate     ↵ to select     Esc to close