You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/guide/language/exception.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,12 @@ let getItem theList => {
17
17
};
18
18
19
19
let result = try (getItem [1, 2, 3]) {
20
-
| Not_found => print_endline "Item not found!"
20
+
| Not_found => 0 /* Default value if getItem throws */
21
21
};
22
22
```
23
23
24
+
Note that the above is just for demonstration purposes; in reality, you'd return an `option int` directly from `getItem` and avoid the `try` altogether.
25
+
24
26
You can directly match on exceptions _while_ getting another return value from a function:
0 commit comments