swig/Examples/test-suite/ocaml/li_std_except_runme.ml
Zackery Spytz e5b8b5a164 [OCaml] Some exception improvements
The OCaml module's exception handling code was poorly designed,
gave confusing exception messages, and was vulnerable to buffer
overflows.

The OCaml module's SWIG_exception_() was adding a useless newline to
the end of the exception message.

In some cases, the integer value of f.e. SWIG_TypeError was being added
to the exception message.

The unneeded else in the OCaml module's SWIG_contract_assert() macro
was causing -Wmisleading-indentation warnings.

The OCaml module's exception handling code now mirrors that of the
Java module.

Add Lib/ocaml/std_except.i.
Add multiple runtime tests.
2019-02-07 16:25:10 -07:00

18 lines
1.2 KiB
OCaml

open Swig
open Li_std_except
let _ =
let t = new_Test '() in
try let _ = t -> throw_bad_cast () in assert false with Failure s -> ();
try let _ = t -> throw_bad_exception () in assert false with Failure s -> ();
try let _ = t -> throw_domain_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_exception () in assert false with Failure s -> ();
try let _ = t -> throw_invalid_argument () in assert false with Invalid_argument s -> assert (s = "oops");
try let _ = t -> throw_length_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_logic_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_out_of_range () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_overflow_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_range_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_runtime_error () in assert false with Failure s -> assert (s = "oops");
try let _ = t -> throw_underflow_error () in assert false with Failure s -> assert (s = "oops");
;;