File: ocaml_runtime_exc_1.ml

package info (click to toggle)
lwt 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,284 kB
  • sloc: ml: 22,030; ansic: 7,167; makefile: 92; python: 62
file content (29 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
   details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)

(* set the exception filter being tested *)
let () = Lwt.Exception_filter.(set handle_all_except_runtime)

(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
   different way than other exceptions and they leave the Lwt main loop in an
   inconsistent state where it cannot be restarted. Indeed, attempting to call
   [Lwt_main.run] again after it has crashed with a runtime exception causes a
   "Nested calls to Lwt_main.run are not allowed" error.

   For this reason, we run this test as its own executable rather than as part
   of a larger suite. *)

open Lwt.Syntax

let test () =
  try
    let () = Lwt_main.run (
      let* () = Lwt.pause () in
      if true then raise Out_of_memory else Lwt.return_unit
    ) in
    Printf.eprintf "Test run+raise failure\n";
    Stdlib.exit 1
  with
    | Out_of_memory -> ()

let () = test ()