Defer, panic, and recover the go blog. Capturing panic in golang. ask question asked 4 years, 4 months ago. active 2 years, 7 months ago. viewed 9k times 19. 9. we have a large-ish golang application that uses the logger (actually, a custom logger), to write output to a log file that is periodically rotated. however, when an application crashes or panic's, those messages go to. Panic is used when the program, or its part, has reached an unrecoverable state. when panic is called, including implicitly for run-time errors such as indexing a slice out of bounds or failing a type assertion, it immediately stops execution of the current function and begins unwinding the stack of the goroutine, running any deferred functions. Some golang official packages use panic/defer+recover as throw/catch, but only when they need to unwind a large call stack. in golang's json package using panic/defer+recover as throw/catch is the most elegant solution. Panic in golang in go language, panic i...