Go defer, panic and recover: Advanced Test


This advanced Go test covers defer, panic and recover, the parts of Go control flow that most often behave differently from what developers expect. Questions check the last-in, first-out order of deferred calls, why deferred call arguments are evaluated when defer runs while closures read variables later, how a deferred closure can change a named result but not an anonymous one, how recover converts a runtime panic such as integer division by zero into an error, why recover returns nil outside a deferred function, why a panic in a goroutine cannot be recovered by main and crashes the whole program, that deferred calls still run during a panic, why defer inside a loop waits for the function to return and os.Exit skips every deferred call, and where execution continues after a recovered panic. Every question is a complete program you can run with go run in the Go sandbox. The test has 10 multiple-choice questions with correct answers and an explanation for each.

Comments

No comments yet. Be the first to share your thoughts.
10 questions
Advanced
0.0 (0)

Author

Software engineer and the creator of the Bytestark learning platform