forked from purescript/purescript-exceptions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException.js
More file actions
51 lines (44 loc) · 938 Bytes
/
Exception.js
File metadata and controls
51 lines (44 loc) · 938 Bytes
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
42
43
44
45
46
47
48
49
50
51
export function showErrorImpl(err) {
return err.stack || err.toString();
}
export function error(msg) {
return new Error(msg);
}
export function errorWithCause(msg) {
return function(cause) {
return new Error(msg, { cause });
};
}
export function message(e) {
return e.message;
}
export function name(e) {
return e.name || "Error";
}
export function stackImpl(just) {
return function (nothing) {
return function (e) {
return e.stack ? just(e.stack) : nothing;
};
};
}
export function throwException(e) {
return function () {
throw e;
};
}
export function catchException(c) {
return function (t) {
return function () {
try {
return t();
} catch (e) {
if (e instanceof Error || Object.prototype.toString.call(e) === "[object Error]") {
return c(e)();
} else {
return c(new Error(e.toString()))();
}
}
};
};
}