Skip to content

Commit 81e8567

Browse files
committed
add example of &throw-context use
Signed-off-by: Sean Corfield <[email protected]>
1 parent 2a0b8d4 commit 81e8567

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ Enhanced throw and catch for Clojure
109109

110110
The wrapper is available via the `:wrapper` key in `&throw-context`.
111111

112+
```clojure
113+
user=> (defn foo [x]
114+
#_=> (throw (ex-info "important message" {:value x})))
115+
#_=>
116+
#_=> (defn -main []
117+
#_=> (try+
118+
#_=> (foo 5)
119+
#_=> (catch Object e
120+
#_=> (println "caught" e &throw-context))))
121+
#'user/foo
122+
#'user/-main
123+
user=> (-main)
124+
caught {:value 5} {:object {:value 5}, :message important message, :cause nil,
125+
:stack-trace #object[[Ljava.lang.StackTraceElement...],
126+
:wrapper #error {
127+
:cause important message
128+
...},
129+
:throwable #error {...}}
130+
```
131+
112132
Between being thrown and caught, a wrapper may be further wrapped by
113133
other Exceptions (e.g., instances of `RuntimeException` or
114134
`java.util.concurrent.ExecutionException`). `try+` sees through all

0 commit comments

Comments
 (0)