3 ms·
> "Go doesn't have exceptions" is mostly misleading. It's worded too strongly perhaps. While `panic` behavior is similar to `java.lang.Exception`, it is not i
by libria 11y ago
> "Go doesn't have exceptions" is mostly misleading.
It's worded too strongly perhaps. While `panic` behavior is similar to `java.lang.Exception`, it is not idiomatic to panic on problems like IOException/SQLException. They are detected by return codes to be handled immediately, rather than a broad swath of code wrapped in `try`.
This in Java:
try
code
code
code
catch errA
handle
catch errB
handle
catch errC
handle
Would be this in Go:
code
handle errA
code
handle errB
code
handle errC
It's fair to say "Go doesn't use exceptions" since Go doesn't use panics for common error handling.