Panic and recover
suggest changeThis 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 exceptions 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents