Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

70 рядки
1.6 KiB

  1. %% a module that crashes in just about every way possible
  2. -module(crash).
  3. -behaviour(gen_server).
  4. -compile([export_all]).
  5. start() ->
  6. gen_server:start({local, ?MODULE}, ?MODULE, [], []).
  7. init(_) ->
  8. {ok, {}}.
  9. handle_call(undef, _, State) ->
  10. {reply, ?MODULE:booger(), State};
  11. handle_call(badfun, _, State) ->
  12. M = booger,
  13. {reply, M(), State};
  14. handle_call(bad_return, _, _) ->
  15. bleh;
  16. handle_call(case_clause, _, State) ->
  17. case State of
  18. goober ->
  19. {reply, ok, State}
  20. end;
  21. handle_call(if_clause, _, State) ->
  22. if State == 1 ->
  23. {reply, ok, State}
  24. end;
  25. handle_call(try_clause, _, State) ->
  26. Res = try tuple_to_list(State) of
  27. [A, B] -> ok
  28. catch
  29. _:_ -> ok
  30. end,
  31. {reply, Res, State};
  32. handle_call(badmatch, _, State) ->
  33. {A, B, C} = State,
  34. {reply, [A, B, C], State};
  35. handle_call(function_clause, _, State) ->
  36. {reply, function(State), State};
  37. handle_call(badarith, _, State) ->
  38. Res = 1 / length(tuple_to_list(State)),
  39. {reply, Res, State};
  40. handle_call(badarg1, _, State) ->
  41. Res = list_to_binary(["foo", bar]),
  42. {reply, Res, State};
  43. handle_call(badarg2, _, State) ->
  44. Res = erlang:iolist_to_binary(["foo", bar]),
  45. {reply, Res, State};
  46. handle_call(system_limit, _, State) ->
  47. Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
  48. {reply, Res, State};
  49. handle_call(noproc, _, State) ->
  50. Res = gen_event:call(foo, bar, baz),
  51. {reply, Res, State};
  52. handle_call(badarity, _, State) ->
  53. F = fun(A, B, C) -> A + B + C end,
  54. Res = F(State),
  55. {reply, Res, State};
  56. handle_call(Call, From, State) ->
  57. {reply, ok, State}.
  58. terminate(_, _) ->
  59. ok.
  60. function(X) when is_list(X) ->
  61. ok.