Skip to content

Commit 7a98402

Browse files
authored
Merge pull request #300 from sogaiu/add-try-examples
Add try examples
2 parents eec6780 + a7ec6e4 commit 7a98402

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

examples/try.janet

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# when no error, return result of `body`
2+
(try
3+
(do
4+
:not-much
5+
true)
6+
([_]
7+
:not-reached))
8+
# -> true
9+
10+
# when an error, return result of `catch`
11+
(try
12+
(error :a-value)
13+
([e]
14+
(type e)))
15+
# -> :keyword
16+
17+
# fiber wrapping `body` can be available on error
18+
(try
19+
(error "fun")
20+
([_ fib]
21+
(type fib)))
22+
# -> :fiber
23+

0 commit comments

Comments
 (0)