Skip to content

Commit 278df84

Browse files
committed
docs(core): documentation and example for protect
1 parent b3d19e9 commit 278df84

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: src/RescriptCore.res

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ type nullable<+'a> = Js.nullable<'a>
6969

7070
let panic = Core__Error.panic
7171

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+
*/
7288
let protect = (~finally, f) => {
7389
let result = try f() catch {
7490
| exn =>

0 commit comments

Comments
 (0)