LWN.net Logo

Uses

Uses

Posted Mar 31, 2012 7:56 UTC (Sat) by fdr (subscriber, #57064)
In reply to: Uses by Cyberax
Parent article: Go version 1 released

If one needs to short circuit for a major fault, use panic/recover. Accrue low-level cleanup actions using defer expressions. Done. I had the same problem you describe and asked some Go-people about it, and then pointed me to a module that used that pattern. It works fine, and doesn't even require a large-scale understanding of the code using said pattern.

panic and recover are there to help with major faults and stack unwinding, and return codes for detailed error recovery that, frankly, are mechanically ugly to complete without being in the low-level mechanism near the failure.

The convention is "must" will panic if something goes wrong. must really is lowercase here, because one is not to panic across library boundaries.


(Log in to post comments)

Uses

Posted Mar 31, 2012 17:00 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

Duh. panic/recover is a lame implementation of exceptions. So one certainly can use them for these scenarios.

The problem is, they've squandered opportunity to do something genuinely better, like enforcing the exception safety.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds