The Dongola Times

(Anachronistic) Dispatches from the Kingdom of Makuria.
13th of June, 2012

panic/defer/recover is not Superior to try-catch

It may be deemed obvious that, since panic/defer/recover as implemented in Go, together with the capacity to return multiple values easily, is directly equivalent to the try-catch scheme implemented in Java, but I have something more to add.

The Go scheme is also less-convenient, because it requires explicit handling of error values returned, but idiom—the ultimate arbiter of whether a feature is a feature—has shown that the common use of this scheme in Go is to just re-throw errors caught, hence the very common if e != nil {panic(e)} expression.
It is also less error-prone, a small way, because at least the throws are explicit at all levels. But it is just as inconvenient as it is safe.
What, then, shall we say?
This makes me think that the cumbersome nature of handling failure is there to stay in an equivalent program. Error-handling cannot be abstracted away. This is why languages that handle it very cleanly—Haskell, for example—are quite irritating when they do handle error cases, while languages where it is possible to pretend and lie to oneself that error-handling is not compulsory and dauntingly-complex are very sweet to program in, like Ruby.
One of those things, like the Heisenberg Uncertainty Principle or Gödel’s Incompleteness Theorems (“Gödelian points”, as Iain McGilchrist calls them) may be this thing that if error-handling is going to be reliable, it will be cumbersome and explicit.



Posted by e-mail.