[erlang-questions] error message interpretation

Manfred Lotz manfred.lotz@REDACTED
Mon Dec 25 18:28:40 CET 2006


Hi there,
I'm a beginner to erlang and I tried the following module:

-module(mytimer).
-export([start/2,timer/3,cancel/1]).

timeout(Time,Alarm) ->
    spawn(mytimer,timer,[Time,Alarm,self()]).

cancel(Timer) -> 
    Timer ! cancel.

timer(Time,Alarm,Pid) ->
    receive
	cancel -> Pid ! "Timer cancelled"
    after Time -> Pid ! Alarm
    end.

start(Time,Alarm) ->
    timeout(Time,Alarm),
    receive 
	Alarm ->
	    io:format("~w~n",[Alarm]);
	cancel -> 
	    io:fwrite("timer cancelled~n",[])
    end.


Now when calling 
mytimer:start(1000,"Wakeup").
in the erl shell this works fine:

However, when calling timeout directly: mytimer:timeout(1000,"Wakeup").
I get this (unexpectedly):

=ERROR REPORT==== 25-Dec-2006::18:25:31 ===
Error in process <0.122.0> with exit value: {undef,[{mytimer,timeout,
[1000,"Wakeup"]},{erl_eval,do_apply,5},{shell,exprs,6},
{shell,eval_loop,3}]}

** exited: {undef,[{mytimer,timeout,[1000,"Wakeup"]},
                   {erl_eval,do_apply,5},
                   {shell,exprs,6},
                   {shell,eval_loop,3}]} **

Erlang error messages look pretty cryptic to me. Can anybody explain to
me what the error message tells me?


-- 
Manfred




More information about the erlang-questions mailing list