News for hackers. Stuff that matters.
Re:Go 1.3 is released by collinvandyck76 on Wednesday June 18, 2014 @11:25PM (#7914245)
If you're talking about panics, you can only handle them in defer funcs if I'm not mistaken, which makes them significantly different from exceptions that I'm used to that can be caught in any part of the code. The dependency on defer in my opinion makes them unusable as typical exceptions in my case. This was perhaps the intent, making panics and the recoveries thereof truly exceptional and painful, pushing one towards the normal error handling semantics, which is what I dislike.
Re:Go 1.3 is released by cmelbye on Thursday June 19, 2014 @12:47AM (#7914521)
It's true that you can only handle them in defer funcs, but the defer func could be anywhere up the stack, not just the current function you're inside.

(I'm not sure if that was your understanding or not)

"The panic and recover functions behave similarly to exceptions and try/catch in some other languages in that a panic causes the program stack to begin unwinding and recover can stop it. Deferred functions are still executed as the stack unwinds. If recover is called inside such a deferred function, the stack stops unwinding and recover returns the value (as an interface{}) that was passed to panic."

https://code.google.com/p/go-wiki/wiki/PanicAndRecover

Re:Go 1.3 is released by dragonwriter on Thursday June 19, 2014 @01:32AM (#7914606)
> If you're talking about panics, you can only handle them in defer funcs if I'm not mistaken,

That's true...but no different from "exceptions can only be caught in catch blocks".

> which makes them significantly different from exceptions that I'm used to that can be caught in any part of the code.

It doesn't make them any different from exceptions -- just as a catch block can be anywhere up the call chain, a deferred function can have been set anywhere up the chain.

Defer is basically "finally", except the position is different, and "recover" inside it lets it also do what "catch" does.