package devkit

  1. Overview
  2. Docs
Development kit - general purpose library

Install

Dune Dependency

Authors

Maintainers

Sources

devkit-1.20210120.tbz
md5=47338eaae436aba40abd4d194ee40054
sha256=499b050b73643f6ad7349a41485539d4166d149a07fba59cb6841f508c0297f8
sha512=6a5bf77061d390ddb331ed3d5891a5c56502be91f0eff6846202f658ebfa97ef57695d7a192cbdad4c7b8835f5665df3ea4375daf46930334ebbd9a07f00feca

doc/src/devkit.core/exn.ml.html

Source file exn.ml

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
30
31
32
33
34
35
36
37
38
39
40
41
(**
  Dealing with exceptions
*)

open Printf
open ExtLib

type 'a result = [ `Ok of 'a | `Exn of exn ]

let catch f x = try Some (f x) with _ -> None
let default def f x = try f x with _ -> def
let suppress f x = try f x with _ -> ()
let map f x = try `Ok (f x) with exn -> `Exn exn

let to_string exn =
  match exn with
  | Unix.Unix_error (e,f,s) -> sprintf "Unix_error %s(%s) %s" f s (Unix.error_message e)
  | Curl.CurlException (_,n,s) -> sprintf "Curl.CurlException(%u,%s)" n s
  | Pcre.Error err -> sprintf "Pcre.Error(%s)"
    begin match err with
    | Partial -> "Partial"
    | BadPartial -> "BadPartial"
    | BadPattern(m,p) -> sprintf "BadPattern(%s,%i)" m p
    | BadUTF8 -> "BadUTF8"
    | BadUTF8Offset -> "BadUTF8Offset"
    | MatchLimit -> "MatchLimit"
    | RecursionLimit -> "RecursionLimit"
    | InternalError s -> sprintf "InternalError(%s)" s
    | _ -> Printexc.to_string exn
    end
  | exn -> Printexc.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
  ksprintf fails fmt

let invalid_arg fmt = ksprintf invalid_arg fmt

let get_backtrace () = String.nsplit (Printexc.get_backtrace ()) "\n"
OCaml

Innovation. Community. Security.