Version française
Home     About     Download     Resources     Contact us    
Browse thread
Seeking exception source
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <ncannasse@m...>
Subject: Re: [Caml-list] Seeking exception source
>>> I am occasionally annoyed by Not_found propagating to my
>>> top level function .. meaning the error could be anywhere
>>> at all in my program.
>>
>>
>> At that time the best is to run your program in bytecode with debug infos 
>> using ocamlrun -b so you'll get full backtrace informations. It would be 
>> better for such debug informations (not all the types but only the 
>> bytecode -> source positions) to be included by default, and always have 
>> backtrace turned on.
>
> In many cases this is completely inadequate. The AS/Xcaml application 
> server, for example, cannot terminate on an uncaught exception in a 
> program module. The main loop must catch the exception and do its best to 
> report it, without aborting the execution of the server. This means that I 
> need to get the backtrace within Ocaml code by applying some kind of 
> function to the exception object. I tried to write a C function providing 
> this kind of information, but I never managed to get it to work.
>
> Alex

Yes I agree, this is not all the time easy to get exceptions backtraces 
since it's only possible for uncaught ones. At some time I managed to modify 
the Ocaml interpreter to make it work, by exporting some C inner interpreter 
functions but I'm not sure it was a correct hack.

On the NekoVM which some design points are inspired by the OCaml VM, I 
recently added exception stack traces. In fact, I was thinking that this 
will cost more performances than it actualy did. The impact on the 
bootstrapping time of NekoML was quite low. It's true that the compiler 
being written in an ML language, quite often exceptions are used to control 
the flow of the program (Not_found , Eof and Exit among others). But since 
in general the position of catching is just a few calls away from the throw, 
you don't have to unwind a lot of debug informations.

It is also useful in that case to have a "reraised" semantic that will keep 
the stack when an execption is filtered. But OCaml have that. Having full 
exceptions backtraces plus call stack traces available at anytime is a big 
plus when working on the NekoML compiler. The tagged union printers 
automaticaly generated and carried with instances are helping a lot too, 
since you can "print" polymorphicaly any runtime value. I think this is very 
small things that would greatly ease the everyday ocaml programmer life.

Nicolas Cannasse