3 ms·
The most bothersome thing is that at least one other language has a working version of what Go tried to go for: Erlang. Erlang has exceptions (as go does, but
by masklinn 14y ago
The most bothersome thing is that at least one other language has a working version of what Go tried to go for: Erlang.
Erlang has exceptions (as go does, but does not pretend it doesn't have them), but they're generally "faults": developers don't normally throw or catch exceptions within a process, they're left to kill the process and signal to the supervision tree.
Instead, erlang functions return ad-hoc tagged unions, tagged with the atoms `ok` for success or `error` for failure, and this union is pattern-matched on. The pattern match can be a case for handling the error:
case might_break(Something) of
{ok, Value} -> handle_correct_case(Value);
{error, Reason} -> handle_error(Reason)
end
but if a developer doesn't want to handle the error and wants things to blow up in case of error, it's as simple as:
{ok, Value} = might_break(something)
If `might_break` returns an error-tagged tuple, this will throw a badmatch.
- masklinn 14y ago(and for those who were wondering, a function which may error out but has no "value" to return, such as a print, will just return the atom `ok` in case of successful execution)