forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve backtraces in match ... with exception e -> ...
When translating into Lambda we treat the case of exception handlers in match forms in the same way as exception handler in try .. with in order to preserve backtraces. A small test is included as well.
- Loading branch information
Showing
5 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
(* 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 = | ||
match | ||
f msg 5 | ||
with | ||
| _ -> | ||
(* value return does not happen *) | ||
assert false | ||
| exception (Error "a") -> | ||
print_string "a"; print_newline(); 0 | ||
| exception (Error "b" as exn) -> | ||
(* this should Re-raise, appending to the current backtrace *) | ||
print_string "b"; print_newline(); raise exn | ||
| exception (Error "c") -> | ||
(* according to the current re-raise policy (a static condition), | ||
this does not re-raise *) | ||
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 [| |] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
a | ||
No exception | ||
b | ||
Uncaught exception Backtrace3.Error("b") | ||
Raised at file "backtrace3.ml", line 7, characters 21-32 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 11, characters 4-11 | ||
Re-raised at file "backtrace3.ml", line 20, characters 47-50 | ||
Called from file "backtrace3.ml", line 28, characters 11-23 | ||
Uncaught exception Backtrace3.Error("c") | ||
Raised at file "backtrace3.ml", line 24, characters 12-23 | ||
Called from file "backtrace3.ml", line 28, characters 11-23 | ||
Uncaught exception Backtrace3.Error("d") | ||
Raised at file "backtrace3.ml", line 7, characters 21-32 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 7, characters 42-53 | ||
Called from file "backtrace3.ml", line 11, characters 4-11 | ||
Called from file "backtrace3.ml", line 28, characters 11-23 | ||
Uncaught exception Invalid_argument("index out of bounds") | ||
Raised by primitive operation at file "backtrace3.ml", line 28, characters 14-22 |