diff options
Diffstat (limited to 'ocaml-binary-annot/testsuite/tests/backtrace/backtrace2.ml')
| -rw-r--r-- | ocaml-binary-annot/testsuite/tests/backtrace/backtrace2.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ocaml-binary-annot/testsuite/tests/backtrace/backtrace2.ml b/ocaml-binary-annot/testsuite/tests/backtrace/backtrace2.ml new file mode 100644 index 0000000000..1f969b2a5a --- /dev/null +++ b/ocaml-binary-annot/testsuite/tests/backtrace/backtrace2.ml @@ -0,0 +1,28 @@ +(* A test for stack backtraces *) + +exception Error of string + +let rec f msg n = + if n = 0 then raise(Error msg) else 1 + f msg (n-1) + +let g msg = + try + f msg 5 + with Error "a" -> print_string "a"; print_newline(); 0 + | Error "b" as exn -> print_string "b"; print_newline(); raise exn + | Error "c" -> raise (Error "c") + +let run args = + try + ignore (g args.(0)); print_string "No exception\n" + with exn -> + Printf.printf "Uncaught exception %s\n" (Printexc.to_string exn); + Printexc.print_backtrace stdout + +let _ = + Printexc.record_backtrace true; + run [| "a" |]; + run [| "b" |]; + run [| "c" |]; + run [| "d" |]; + run [| |] |
