caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exceptions and backtraces
@ 2015-09-09 19:18 Anders Peter Fugmann
  2015-09-09 19:59 ` Anders Peter Fugmann
  0 siblings, 1 reply; 5+ messages in thread
From: Anders Peter Fugmann @ 2015-09-09 19:18 UTC (permalink / raw)
  To: caml-list

Hi,

I'm trying to understand what to expect from backtraces when an 
exception is raised.

The library reference says:
---------------
val print_backtrace : out_channel -> unit

Printexc.print_backtrace oc prints an exception backtrace on the output 
channel oc. The backtrace lists the program locations where the 
most-recently raised exception was raised and where it was propagated 
through function calls.
---------------

The documentation seems to suggest that every function call site leading 
up to the exception would be part of the backtrace. However, when I 
execute the following program:
---------------
let trace () =
   let open Printexc in
   get_callstack 2
   |> backtrace_slots
   |> (function Some [| _;s |] -> s)
   |> Slot.location
   |> (function Some l -> l.line_number)
   |> Printf.printf "At Line: %d\n"

exception Stop
let a () = trace (); raise Stop
let b () = trace (); a ()
let ()   = trace (); b ()
--------------
The code produces (both byte and native compilation):
(ocaml 4.02.3 and 4.03-trunk)

At Line: 13
At Line: 12
At Line: 11
Fatal error: exception Exception.Stop
Raised at file "exception.ml", line 11, characters 27-31
Called from file "exception.ml", line 13, characters 21-25

The backtrace does not record the function call at line 12, even though 
the information is there (accessible though 'get_callstack'), so I 
assume that inlining is not causing the behaviour.

Is it expected that the backtrace does not contain a reference for line 
12, or is there some exception handling optimization I should be aware of?

/Anders

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-10 11:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-09 19:18 [Caml-list] Exceptions and backtraces Anders Peter Fugmann
2015-09-09 19:59 ` Anders Peter Fugmann
2015-09-10  9:45   ` Jesper Louis Andersen
2015-09-10 10:54     ` Anders Fugmann
2015-09-10 11:09       ` Jesper Louis Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).