3 ms·
> Lack of exception handling is the biggest reason I haven't used Go for much. Go does exception handling with panic, recover and its reflection syntax.
by EdiX 14y ago
> Lack of exception handling is the biggest reason I haven't used Go for much.
Go does exception handling with panic, recover and its reflection syntax.
- trailfox 14y agoSo if I'm reading from a file I should use panic recover and not return code checking?? That's not what I've seen in the docs.
- jlgreco 14y agoYou seem to be missing the difference between "can you do it" and "should you do it". The reason that you should not is because doing so is not idiomatic Go. You are completely able to do so though.
- NateDad 14y agoUsing panic and recover is strongly discouraged, and in the rare cases where it makes the code significantly simpler, panics should never cross package boundaries (which is to say, you should never have a public API that can panic, unless you fully expect the panic to take down the process).
- EdiX 14y agoUsing panics for control flow or having panics cross library boundaries is strongly discouraged, otherwise they are fine. Go's own standard library uses them internally in several places. Even then discouraging panics is very different from not having them.