[erlang-questions] erl_syntax[_lib] error handling
Anthony Ramine
n.oxyde@REDACTED
Sat Apr 19 13:51:43 CEST 2014
I think the defensive programming in syntax_tools should be removed entirely.
How revert/1 manages to sometimes return custom nodes as is but sometimes crash and sometimes return the actual reverted node drives me insane.
--
Anthony Ramine
Le 19 avr. 2014 à 13:39, Richard Carlsson <carlsson.richard@REDACTED> a écrit :
> On 2014-02-24 21:21 , Tuncer Ayaz wrote:
>> erl_syntax and erl_syntax_lib seem to favor throwing exceptions over
>> returning error terms. I found this hard to use due to the missing
>> documenation of what exceptions can be thrown by each function. Only
>> erl_syntax_lib:analyze_application/1 documents one exception it might
>> throw, and the documentation for other funs just states the following:
>> "An exception is thrown if..."
>>
>> The only way to handle erl_syntax[_lib] errors I've seen so far is to
>> catch all exceptions, but that can filter/suppress any kind of
>> exception.
>>
>> What's the recommended way to handle erl_syntax[_lib] errors?
>
> Hi Tuncer. erl_syntax does not try to be systematic about what kind of exception gets generated when the input is bad; that would probably make the code grow by 50% In general, it will be a function_clause, case_clause or badmatch, but there's no good way of separating these from an actual bug in erl_syntax. The intended way to use erl_syntax with unknown input is to use the type/1 function (throws badarg error if it's not a valid AST) and predicates like is_atom/1 to test the input before trying to deconstruct it.
>
> /Richard
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list