1. 程式人生 > >7.1 錯誤處理-Catch和Throw

7.1 錯誤處理-Catch和Throw

parse_list1(['[',']' | T]) ->
    {nil, T};
parse_list1(['[', X | T]) when integer(X) ->
    {Tail, T1} = parse_list_tail1(T),
    {{cons, X, Tail}, T1};
parse_list1(X) ->
    throw({illegal_token, X}).

parse_list_tail1([',', X | T]) when integer(X) ->
    {Tail, T1} = parse_list_tail1(T),
    {{cons, X, Tail}, T1};
parse_list_tail1([']' | T]) ->
    {nil, T};
parse_list_tail1(X) ->
    throw({illegal_list_tail, X}).