我正在尝试使用Dire库处理异常。像这样:
Y
但总是出错:
ExceptionInfo clj-http:status 404 clj-http.client / wrap-exceptions / fn - 3052(client.clj:196)
我试图将java.lang.Exception更改为clojure.lang.ExceptionInfo,效果相同。我错过了什么吗?
答案 0 :(得分:4)
clj-http显然使用Slingshot,参见clj-http documentation on exceptions。 Slingshot的throw+
操作可以抛出任何类型的对象,而不仅仅是异常(Throwable
s)。 clj-http文档有一个例子:
; Response map is thrown as exception obj.
; We filter out by status codes
(try+
(client/get "http://some-site.com/broken")
(catch [:status 403] {:keys [request-time headers body]}
(log/warn "403" request-time headers))
(catch [:status 404] {:keys [request-time headers body]}
(log/warn "NOT Found 404" request-time headers body))
(catch Object _
(log/error (:throwable &throw-context) "unexpected error")
(throw+)))
此外,Dire documentation有一个如何与Slingshot集成的示例:基本上您应该能够删除[:status 404]
而不是java.lang.Exception
。