--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVLmE9KxnYTC1rbJHE9E1WHpSdGsVwHDT2CH%3DfK_2ZoGQ%40mail.gmail.com.
Hmmm. Seems like there shouldn't be a panic and recover in the language then - just always abort - or things are too risky. Or make it a private stdlib localized/internal capability.
But how can you manage that in a library situation? The is no “throws” type declaration, so how can you be certain that the panic is actually raised by your code if you’re calling library routines in the same function? I guess you could wrap every call but that seems tedious - so it seems more “you can’t use panic/recover if you call ANY code not your own” - which also seems difficult to ensure.
Wouldn’t it be better (at least safer) to make the standard that you need to use defer to ensure resources are clean as ANY line might panic? or you need to run your app in a “any panic crashes mode” - which again seems problematic for internal library code.
On Dec 8, 2025, at 9:46 PM, Ian Lance Taylor <ia...@golang.org> wrote:
I don’t agree with that. The entire premise of RAII in C++ is to ensure the proper management of resources in the context of exceptions. Sure you can write code that doesn’t do that but it would be incorrect (and difficult to debug).
Fair enough. If you find the time I’d love a response or a link to some details that supports your position. I’ll readily agree that RAII is not used universally due to some performance concerns (like using shared_ptr everywhere) but in concept I believe it solves the dandling resources concern with exceptions. Java takes a different approach with try/finally (which I consider close enough to defer in Go)
On Dec 9, 2025, at 12:39 AM, Robert Engels <rob...@me.com> wrote:
As that article points out, it is a combination of C++ expression evaluation order and RAII. If you understand the expression evaluation rules you can write 100% resource safe code using RAII.