We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b3d19e9 commit 278df84Copy full SHA for 278df84
src/RescriptCore.res
@@ -69,6 +69,22 @@ type nullable<+'a> = Js.nullable<'a>
69
70
let panic = Core__Error.panic
71
72
+/**
73
+ `protect(~finally, f)`
74
+
75
+ Tries to execute the function `f`, and ensures that `finally` will be called
76
+ whether `f` raises an exception or not.
77
78
+ Any exception raised by `f` will be re-raised in order to be handled by the
79
+ user. If `finally` raises, then that exception will be emitted instead, and
80
+ any exception raised by `f` will go unnoticed.
81
82
+ ```res example
83
+ try protect(~finally=() => Js.log("finally"), () => failwith("oh no!")) catch {
84
+ | Failure(err) => Js.log(err)
85
+ }
86
+ ```
87
+*/
88
let protect = (~finally, f) => {
89
let result = try f() catch {
90
| exn =>
0 commit comments