Markus Mottl avatar Markus Mottl committed ffd19a7

Fixed error module initialization bug due to missing merge with Olivier

Comments (0)

Files changed (2)

 
 exception Gsl_exn of (errno * string)
 
-external raise_caml_exn : bool -> unit = "ml_gsl_error_init"
+
+let default_handler errcode =
+  raise (Gsl_exn errcode)
+let handler =
+  ref default_handler
+
+external setup_caml_error_handler : bool -> unit = "ml_gsl_error_init"
 
 let _ = 
-  Callback.register_exception "mlgsl_exn" (Gsl_exn (CONTINUE, ""))
+  Callback.register_exception "mlgsl_exn" (Gsl_exn (CONTINUE, ""));
+  Callback.register "mlgsl_err_handler" handler
 
 let init () = 
-  raise_caml_exn true
+  setup_caml_error_handler true
 
 let uninit () = 
-  raise_caml_exn false
+  setup_caml_error_handler false
 
 external strerror : errno -> string = "ml_gsl_strerror"
 
 
 exception Gsl_exn of (errno * string)
 
+(** [Gsl_error.init ()] setups the GSL error handler so that
+    the OCaml function {!Gsl_error.handler} gets called in case of an error. *)
 val init   : unit -> unit
+
+(** [Gsl_error.uninit ()] reverts the GSL error handler to its previous definition.
+    The default GSL error simply aborts the program. *)
 val uninit : unit -> unit
 
-external strerror : errno -> string = "ml_gsl_strerror"
+(** The OCaml handler for GSL errors. Initially set to {!Gsl_error.default_handler}.
+    If the function returns, the error is ignored and execution of the GSL function continues.
+
+    Redefine it so as to ignore some particular errors ([EOVRFLW] or
+    [EUNDRFLW] for instance). *)
+val handler : (errno * string -> unit) ref 
+
+(** The default OCaml handler for GSL errors. It simply raises the
+    {!Gsl_error.Gsl_exn} exception. *)
+val default_handler : errno * string -> 'a
+
+val strerror : errno -> string
 val string_of_errno : errno -> string
 
 val pprint_exn : exn -> string
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.