Skip to content

Commit

Permalink
exn: preserve backtraces
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Jul 31, 2024
1 parent 8451877 commit c5b26bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion exn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ let to_string exn =
let str = to_string

let fail ?exn fmt =
let fails s = match exn with None -> failwith s | Some exn -> failwith (s ^ " : " ^ to_string exn) in
let fails s =
match exn with
| None -> failwith s
| Some original_exn ->
let exn = Failure (s ^ " : " ^ to_string original_exn) in
Printexc.raise_with_backtrace exn (Printexc.get_raw_backtrace ())
in
ksprintf fails fmt

let invalid_arg fmt = ksprintf invalid_arg fmt
Expand Down

0 comments on commit c5b26bd

Please sign in to comment.