Is it possible to have the line of an error?
Martin J. Logan
mlogan@REDACTED
Wed Jul 9 17:13:17 CEST 2003
Dominic,
Unfortunately I know of no ideal solution to your problem. Here is
the way that I do things. All of my Erlang code is written with OTP and
I use SASL and error logger to provide me with a more detailed account
of what happened in my code before it failed as well as at failure.
I have noticed that many new functional/erlang programmers especially
those from a strictly imperative background(I don't know if you fit
here) tend to write very long functions with many case & if statements
in mimicry of the imperative style and all of its if and else
statements. Take a look at your functions and make sure that they are
concise. Short concise functions will aid in finding and isolating
errors.
Aside from this the only thing that helps in familiarity and focus on
what various functions return. If I see {badmatch, undefined} and I
examine the function that it occurred in and I see, among other things,
an application:get_env I know quite well that it returns undefined if
the configuration value specified is not present.
Cheers,
Martin
On Wed, 2003-07-09 at 04:36, WILLIAMS Dominic wrote:
> Hello,
>
> I have been trying to write Erlang code in the "let it fail" philosophy, e.g.
>
> {ok, Content} = file:read_file(filename:join("c:/tmp","test"))
>
> instead of:
>
> case file:read_file(filename:join("c:/tmp","test")) of
> {ok, Content} ->
> handle_content(Content);
> {error, Reason} ->
> {error, {read_failed,Reason}}
> end.
>
> As a beginner in Erlang, one problem I have with this is that when it does fail, the information provided (from the shell, for example) is sufficient to know there was a badmatch in a given function, but not at which line in the function.
>
> Is it possible to know the line of the failure? I am looking for something like compile options or activating traces, rather than peppering my code with macros and ?LINE...
>
> Cheers,
>
> Dominic.
More information about the erlang-questions
mailing list