I'd say that recover() is not a problem but, instead, a symptom of panic() being available to developers. I'd flip the title and say panic() should be considered harmful. To quote from https://blog.golang.org/defer-panic-and-recover : > The process continues up the stack until all functions in the current goroutine have returned, at which point the program crashes
Any code that invokes panic is very clearly stating that an error has occurred that is completely unrecoverable and the _only_ choice of action that could possibly be taken is to end the program. The recover() builtin must exist to account for the fact that _all_ uses of panic in user space are, in fact, recoverable errors. As someone developing in go, it is infuriating when external libraries (whether 3rd party or std lib) make decisions about when my program should stop. Code related bugs, such as nil pointer dereferences or invalid interface conversions, should result in a process failure just like a segfault in any other runtime. However, some library using the same process ending mechanism to let me know that it doesn't like the format of my string input is unacceptable. On Mon, Apr 24, 2017 at 5:41 AM Christian von Pentz <c...@blackinternet.org> wrote: > On 04/24/2017 11:02 AM, Sokolov Yura wrote: > > I mean: panic usually means programmer error, so if it happens, then > > program behaves incorrectly, and there is always a chance of serious > > state corruption. So, is there reason to recover at all? > > I encountered many cases of panics when using external tools/libraries > which were completely "fine" to recover from. magicmime was such a > package that had a few "hiccups" when used in a multi-threaded > environment mostly due to the underlying libmagic. That being said, very > easy and convenient to recover from, so yeah, I would say recover is a > perfectly valid strategy sometimes. > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.