1. 程式人生 > >8.1 編寫健壯的應用程式-防範錯誤資料

8.1 編寫健壯的應用程式-防範錯誤資料

server(AnalTable) ->
    receive
            {From, {analyse,Seq}} ->
                case catch lookup(Seq, AnalTable) of
                        {'EXIT', _} ->
                            From ! {number_analyser, error};
                        Result ->
                            From ! {number_analyser, Result}
                    end,
                    server(AnalTable);
            {From, {add_number, Seq, Key}} ->
                From ! {number_analyser, ack},
                    case catch insert(Seq, Key, AnalTable) of
                        {'EXIT', _} ->
                            From ! {number_analyser, error},
                                server(AnalTable); % Table not changed
                        NewTable ->
                            server(NewTable)
                    end
        end.