-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
148 additions
and
35 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
14 changes: 14 additions & 0 deletions
14
testsuite/tests/backtrace/backtrace_or_exception.byte.reference
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,14 @@ | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 13, characters 4-13 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 5, characters 10-13 | ||
Called from file "backtrace_or_exception.ml", line 17, characters 8-44 | ||
Re-raised at file "backtrace_or_exception.ml", line 20, characters 4-13 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 29, characters 6-15 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- |
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,43 @@ | ||
exception Exn | ||
|
||
let return_exn ?(raise_it_instead=false) () = | ||
if raise_it_instead then | ||
raise Exn | ||
else | ||
Exn | ||
|
||
let without_reraise () = | ||
match return_exn () with | ||
| Exn as exn | ||
| exception (Exn as exn) -> | ||
raise exn | ||
| _ -> assert false | ||
|
||
let with_reraise () = | ||
match return_exn ~raise_it_instead:true () with | ||
| Exn as exn | ||
| exception (Exn as exn) -> | ||
raise exn | ||
| _ -> assert false | ||
|
||
let trickier () = | ||
try raise Not_found | ||
with e -> | ||
match return_exn () with | ||
| Exn as exn | ||
| exception (Exn as exn) -> | ||
raise exn | ||
| _ -> assert false | ||
|
||
let run f = | ||
try f () | ||
with exn -> | ||
Printf.printf "exception %s\n" (Printexc.to_string exn); | ||
Printexc.print_backtrace stdout; | ||
Printf.printf "---------------------------\n%!" | ||
|
||
let _ = | ||
Printexc.record_backtrace true; | ||
run without_reraise; | ||
run with_reraise; | ||
run trickier |
14 changes: 14 additions & 0 deletions
14
testsuite/tests/backtrace/backtrace_or_exception.native.reference
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,14 @@ | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 13, characters 4-13 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 5, characters 4-13 | ||
Called from file "backtrace_or_exception.ml", line 17, characters 8-44 | ||
Re-raised at file "backtrace_or_exception.ml", line 20, characters 4-13 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- | ||
exception Backtrace_or_exception.Exn | ||
Raised at file "backtrace_or_exception.ml", line 29, characters 6-15 | ||
Called from file "backtrace_or_exception.ml", line 33, characters 6-10 | ||
--------------------------- |
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,13 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
|
||
let f x = | ||
match x with | ||
| `A -> () | ||
| exception Not_found -> () | ||
;; | ||
|
||
[%%expect{| | ||
val f : [< `A ] -> unit = <fun> | ||
|}] |
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,9 @@ | ||
(* TEST | ||
*) | ||
|
||
exception String of string | ||
|
||
let _ = | ||
match "foo" with | ||
| str | exception (String str) -> print_endline str | ||
| exception _ -> print_endline "unexpected exception!" |
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 @@ | ||
foo |
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