smart exceptions

Serge Aleynikov <>
Tue Mar 7 16:57:24 CET 2006


Thomas, thanks for your tips.

Another question: In the attached example when an undefined function is 
called (test case 0) the line number doesn't get written as you can see 
below.  Is this expected?

Serge


$ erlc +'{parse_transform, smart_exceptions}' -pa ../ebin -o .. test.erl
$ erl
Erlang (BEAM) emulator version 5.4.12 [source] [hipe] [threads:0]

Eshell V5.4.12  (abort with ^G)
1> test:test().
{0,
  {'EXIT',{undef,[{abcd,f,[]},
                  {test,'-test/0-lc$^0/1-0-',1},
                  {erl_eval,do_apply,5},
                  {shell,exprs,6},
                  {shell,eval_loop,3}]}}}
{1,{'EXIT',{{test,t,1},{line,12},{error,1}}}}
{2,
  {'EXIT',{{test,t,1},
           {line,16},
           {badarith,[{test,t,1},
                      {test,'-test/0-lc$^0/1-0-',1},
                      {test,'-test/0-lc$^0/1-0-',1},
                      {erl_eval,do_apply,5},
                      {shell,exprs,6},
                      {shell,eval_loop,3}]},
           '/',
           [100,0]}}}
{3,{'EXIT',{{test,t,1},{line,20},match,[{error,abc}]}}}
{4,{error,test}}
{5,
  {'EXIT',{{test,t,1},
           {line,26},
           {bad_error,[{test,t,1},
                       {test,'-test/0-lc$^0/1-0-',1},
                       {test,'-test/0-lc$^0/1-0-',1},
                       {erl_eval,do_apply,5},
                       {shell,exprs,6},
                       {shell,eval_loop,3}]},
           {erlang,error},
           [bad_error]}}}
{6,
  {'EXIT',{{{test,t,1},{line,29},bad_fault},
           [{test,t,1},
            {test,'-test/0-lc$^0/1-0-',1},
            {test,'-test/0-lc$^0/1-0-',1},
            {erl_eval,do_apply,5},
            {shell,exprs,6},
            {shell,eval_loop,3}]}}}
{7,
  {'EXIT',{{test,t,1},
           {line,32},
           {badarg,[{test,t,1},
                    {test,'-test/0-lc$^0/1-0-',1},
                    {test,'-test/0-lc$^0/1-0-',1},
                    {erl_eval,do_apply,5},
                    {shell,exprs,6},
                    {shell,eval_loop,3}]},
           '!',
           [pid,test]}}}
{8,{'EXIT',{{test,t,1},{line,7},function_clause,"\b"}}}



Thomas Lindgren wrote:
> 
> --- Serge Aleynikov <> wrote:
> 
> 
>>1. Am I correct to say that when using smart
>>exceptions, the beam files 
>>in jungerl/lib/smart_exceptions/ebin are only needed
>>at compile-time and 
>>not at run-time?
> 
> 
> With the "normal" use of smart exceptions, you only
> need the transform at compile time.
> 
> (Theoretically, you can also make it plug in other
> stuff to do at an error, but this hasn't really been
> used.)
> 
> 
>>2. Is there a way to use smart_exceptions in order
>>to include 
>>function/line info in the uncaught throw exception?
> 
> 
> I'm not convinced that's a good default behaviour,
> since the thrown value is sometimes used as a valid
> return value. Changing a thrown value may then lead to
> amusing runtime problems as pattern matches fail.
> 
> If you still want to do it, hack the code so that
> throw/1 is rewritten like exit/1. Eh, jungerl seems to
> be very slow, so I can't show you directly ... but it
> should basically be a matter of copy+paste+modify a
> line where a call to exit(Rsn) is detected and
> rewriting the copied line to do the same with throw.
> 
> Note that the code does this rewrite in two ways,
> depending on a compile-time flag. It's pretty
> straightforward, just be sure that you are getting
> your modified version.
> 
> PS. OTP, not that I know if you're thinking about it,
> but if you want to introduce line numbers etc. in
> exceptions, please mail me before you start hacking.
> There are a couple of things to think about, and do,
> to get it right, or, at least, to get it much more
> right than smart_exceptions.
> 
> Best,
> Thomas
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 

-- 
Serge Aleynikov
R&D Telecom, IDT Corp.
Tel: (973) 438-3436
Fax: (973) 438-1464

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060307/e1abc801/attachment.ksh>


More information about the erlang-questions mailing list