Search⌘ K

Run-time Exceptions and Panic

Explore how Go triggers run-time panics during critical errors and how panic stops program execution while ensuring deferred functions run. Understand when and why to use panic in your Go code, and how it propagates through function calls, helping you handle unrecoverable errors effectively.

We'll cover the following...

Run-time panic

When an execution errors occur, such as attempting to index an array out of bounds or a type assertion failing, the Go runtime triggers a run-time panic with a value of the interface type runtime.Error, and the program crashes with a message of the error. This value has a RuntimeError() method, to distinguish it from a normal error.

Panic can also be initiated from code directly: when the error-condition (which we are testing in the code) is so severe and unrecoverable that the ...