[erlang-questions] error message interpretation

Michael McDaniel erlangx@REDACTED
Mon Dec 25 19:14:37 CET 2006


On Mon, Dec 25, 2006 at 06:28:40PM +0100, Manfred Lotz wrote:
> 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
> 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 The function mytimer:timeout/2 is not exported hence has no
 external visibility.  The error message (undef) says it is 
 undefined.

 It works when you call mytimer:start(1000,  "Wakeup"). because, in
 that case, mytimer:timeout/2 is being called from within the module
 where it does have visibility (without having to be exported).

~M



More information about the erlang-questions mailing list