[erlang-questions] Displaying the line number when error occured

Bengt Kleberg <>
Mon May 21 09:13:18 CEST 2007


On 2007-05-21 04:40, June Kim wrote:
...deleted
>> -module(foo).
>> -export([bar/1]).
>>
>> bar(X)->
>>    1+2+3,
>>    5=X.
>>
>> ==============
>>
>> 8> foo:bar(5).
>>
>> =ERROR REPORT==== 18-May-2007::23:08:44 ===
>> Error in process <0.61.0> with exit value:
>> {{badmatch,5},[{foo,bar,1},{shell,exprs,6},{shell,eval_loop,3}]}
>>
>> ** exited: {{badmatch,5},
>>            [{foo,bar,1},{shell,exprs,6},{shell,eval_loop,3}]} **
>>
>> The report isn't very helpful. Is there any way I can see the line
>> number of the source code that the error occured?

i do not know how to get the line number. as an alternative may i 
suggest that you make your functions short? the error report do tell you 
which function, and how, the error occurred.

in the above example you have a sufficiently short function and the 
error report says:
{{badmatch,5},[{foo,bar,1},..
where badmatch means an error with '='. and 5 means that there is a 5 to 
the right of the '=' when you get the badmatch.
{foo,bar,1} means module foo, function bar (with one argument).

this seems impossible to me since the only '=' you have in bar/1 has a 5 
to the left which means that is an ok match with a 5 to the right.
so in this case it is possible to see from the error report that your 
example is in error :-)


bengt
-- 
Those were the days...
    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."



More information about the erlang-questions mailing list