3 ms·
The language doesn't impose this upon you. You can use the exception handling system to pass values around, just like you might in the aforementioned languages.
by randomdata 2y ago
The language doesn't impose this upon you. You can use the exception handling system to pass values around, just like you might in the aforementioned languages. Even Go's standard library does it. Read the encoding/json source sometime.
You might impose it upon yourself when you start to understand the pitfalls of using exceptional handlers for anything other than exceptions, but such is engineering. Everything comes with tradeoffs.
- hot_gril 2y agoWhat's imposed on a Golang user is two choices, panic/recover or regular error handling, and almost always you take the latter. There's no option of using exceptions the same way you would in most other languages.
- randomdata 2y agoSame as all of those other languages mentioned. What gives you the impression that Go is somehow magically different? Or have I misinterpreted you?
- unbrice 2y agoOne technical challenge to using panic to represent normal exceptions is that most go code is then not exception safe. This was a design choice for the ecosystem if not the language itself (see eg: Effective go about panic not crossing package boundaries, or Google's style guide). Within a package it can work, but then you'll find language support lacking. For example defer is scoped to a function so you need to write pretty unusual code to make the equivalent of a try block.