~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to testsuite/tests/backtrace/backtrace2.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 21:35:08 UTC
  • mfrom: (1.1.11 upstream) (12.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110421213508-kg34453aqmb0moha
* Fixes related to -output-obj with g++ (in debian/patches):
  - add Declare-primitive-name-table-as-const-char
  - add Avoid-multiple-declarations-in-generated-.c-files-in
  - fix Embed-bytecode-in-C-object-when-using-custom: the closing
    brace for extern "C" { ... } was missing in some cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* A test for stack backtraces *)
 
2
 
 
3
exception Error of string
 
4
 
 
5
let rec f msg n =
 
6
  if n = 0 then raise(Error msg) else 1 + f msg (n-1)
 
7
 
 
8
let g msg =
 
9
  try
 
10
    f msg 5
 
11
  with Error "a" -> print_string "a"; print_newline(); 0
 
12
     | Error "b" as exn -> print_string "b"; print_newline(); raise exn
 
13
     | Error "c" -> raise (Error "c")
 
14
 
 
15
let run args =
 
16
  try
 
17
    ignore (g args.(0)); print_string "No exception\n"
 
18
  with exn ->
 
19
    Printf.printf "Uncaught exception %s\n" (Printexc.to_string exn);
 
20
    Printexc.print_backtrace stdout
 
21
 
 
22
let _ =
 
23
  Printexc.record_backtrace true;
 
24
  run [| "a" |];
 
25
  run [| "b" |];
 
26
  run [| "c" |];
 
27
  run [| "d" |];
 
28
  run [| |]