Panic recover in Go v.s. try catch in other languages

Panic/Recover are function scoped. It’s like saying that you’re only allowed one try/catch block in each function and the try has to cover the whole function. This makes it really annoying to use Panic/Recover in the same way that java/python/c# etc. use exceptions. This is intentional.
This also encourages people to use Panic/Recover in the way that it was designed to be used. You’re supposed to recover() from a panic() and then return an error value to the caller.

Leave a Comment