27
Jul
Panics are caused by operations like accessing elements outside the bounds of an array, null dereference, closing closed channels, and so on. They are abnormal operations that should be avoided by checks in the code, but sometimes these scenarios are missed, and the panic can crash our application. There might be many reasons to recover from a panic, the most obvious being to "fail gracefully" by finishing cleanup operations and properly reporting the errors before exiting. Panic recovery in Go is based on defers, lets take a look at how they work. Each time the function encounters a defer statement,…