Newbie compilation question

Claes Wikstrom <>
Fri Dec 18 10:54:58 CET 1998


Mark NG writes:
 > 
 > 
 > Hallo !
 > 
 > 
 > When I was writing a program I wrote "list:append/2" in my code instead of
 > the correct one - "lists:append/2".  The compiler fail to notify me of that
 > and when I ran it by spawning a process  it just dies out quitely...
 > 
 > I had to use the Process Manager's tracing facility to find out that it
 > is due to a missing 's' in the function call !
 > 
 > So, my questions is 
 > 1) How can I make the compiler (I am using c:c/1) notify me of undefined 
 >    symbols ?

This we simply cannot do. All references to modules and functions are
resolved at runtime. There is no link phase at all !!!
This is so since we want to be able to load code in the running system
in a flexible way. 

 > 
 > 2) How can I get the error messages of a spawn proces to appear on the shell ?
 > 

This can be done, but it's not easy. This is what happens:

1. The runtime system creates an new process.
2. The process start to execute.
3. The runtime system sees a call to list:append/2 (miss spelled)
4. The runtime system realizes that no module named 'list' is loaded
   so insted it invokes nother module called the error_handler

   Thus the call to list:append(X,Y) is transformd into a call
   error_handler:undefined_function(list, append, [X, Y])

   This error_handler module resides in kernel/src/error_handler.erl

   The error_handler (in kernel/src) will ask the code server to
   search the load_path and try to load a module called list.jam

   If this failes, the error_hanler simply does a call to
   exit({undef,{Module,Func,Args}})
  
   Which will silently exit te process.

However in an environment where we sit and develop we could 
sometimes want to have a different behaviour there, for example
print a little friendly something on stdout saying that we can't find
the module list.erl
This is bad default behaviour though.

As an exercise you could try to modify the error_handler to do
just that and then (maybe in your ~/.erlang) load your own
error_handler instead of the systems.

I know that Arndt Jonason has done just that, he is running
some weird error_handler that tries to correct misspelleded
modules at runtime !!

You can also give the -pa Dir flag to 'erl' and point it
to a directory where a different error_handler resides.

Cheers

/klacke




More information about the erlang-questions mailing list