Exn
Provide utilities for dealing with JS exceptions.
t
RESCRIPT
type tRepresents a JS exception
asJsExn
RESCRIPT
let asJsExn: exn => option<t>stack
RESCRIPT
let stack: t => option<string>message
RESCRIPT
let message: t => option<string>name
RESCRIPT
let name: t => option<string>fileName
RESCRIPT
let fileName: t => option<string>isCamlExceptionOrOpenVariant
RESCRIPT
let isCamlExceptionOrOpenVariant: 'a => boolinternal use only
anyToExnInternal
RESCRIPT
let anyToExnInternal: 'a => exnanyToExnInternal(obj) will take any value obj and wrap it
in a Js.Exn.Error if given value is not an exn already. If
obj is an exn, it will return obj without any changes.
This function is mostly useful for cases where you want to unify a type of a value that potentially is either exn, a JS error, or any other JS value really (e.g. for a value passed to a Promise.catch callback)
IMPORTANT: This is an internal API and may be changed / removed any time in the future.
Examples
RESCRIPTswitch (Js.Exn.unsafeAnyToExn("test")) {
| Js.Exn.Error(v) =>
switch(Js.Exn.message(v)) {
| Some(str) => Js.log("We won't end up here")
| None => Js.log2("We will land here: ", v)
}
}
raiseError
RESCRIPT
let raiseError: string => 'aRaise Js exception Error object with stacktrace
raiseEvalError
RESCRIPT
let raiseEvalError: string => 'araiseRangeError
RESCRIPT
let raiseRangeError: string => 'araiseReferenceError
RESCRIPT
let raiseReferenceError: string => 'araiseSyntaxError
RESCRIPT
let raiseSyntaxError: string => 'araiseTypeError
RESCRIPT
let raiseTypeError: string => 'araiseUriError
RESCRIPT
let raiseUriError: string => 'a