The cost of Go's panic and recover
Published on: 2025-07-03 19:19:11
Some of the wisdom contained in Josh Bloch’s Effective Java book is relevant to Go.
panic and recover are best reserved for exceptional circumstances.
and are best reserved for exceptional circumstances. Reliance on panic and recover can noticeably slow down execution, incurs heap allocations, and precludes inlining.
and can noticeably slow down execution, incurs heap allocations, and precludes inlining. Internal handling of failure cases via panic and recover is tolerable and sometimes beneficial.
Abusing Java exceptions for control flow ¶
Even though my Java days are long gone and Go has been my language of predilection for a while, I still occasionally revisit Effective Java, Joshua Bloch’s seminal and award-winning book, and I never fail to rediscover nuggets of wisdom in it. In item 69 (entitled Use exceptions only for exceptional conditions) of the book’s third edition, Bloch presents an example of abusing Java exceptions for control flow. I’m hesitant to quote the content o
... Read full article.