[eeps] EEP 049: Value-Based Error Handling Mechanisms
Fred Hebert
mononcqc@REDACTED
Fri Oct 23 13:05:00 CEST 2020
I would personally not go for ‘catch’ since its two current uses are for
exception handling whereas here it’s not the case at all.
On Fri, Oct 23, 2020 at 00:47 José Valim <jose.valim@REDACTED> wrote:
>
>
>> I don't know if we have a problem with introducing 'else' as a keyword.
>> Will that potentially break old existing code?
>>
>
> If a new keyword is a contention point, "catch" can be one option:
>
> change_and_backup(File) ->
> begin
> {ok, Value} <~ file:read_file(File),
> NewValue = do_something_with_value(Value),
> ok <~ file:write_file(File ++ ".backup", Value),
> ok <~ file:write_file(File, NewValue),
> NewValue
> catch
> {error, Reason} -> erlang:error({backup_error, Reason}, [File])
> end.
>
> Use begin/catch for local/functional returns and try/catch for
> non-local/imperative returns. It may even make it clearer they are two
> approaches for tackling the same problem.
>
> _______________________________________________
> eeps mailing list
> eeps@REDACTED
> http://erlang.org/mailman/listinfo/eeps
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/eeps/attachments/20201023/e996378e/attachment.htm>
More information about the eeps
mailing list