Skip to content

Commit ee87d55

Browse files
committed
Add section warning against catching Throwables
1 parent 667af93 commit ee87d55

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,29 @@ throw an exception -- throws an exception of a standard type
22402240

22412241
Favor `with-open` over `finally`.
22422242

2243+
=== Catching Throwables [[catching-throwables]]
2244+
2245+
Don't catch `Throwable`. It is a superclass of all Errors and Exceptions in
2246+
Java, and as such, it will swallow _all_ possible Errors. As explained by the
2247+
Java documentation on the `Error` class, "An Error is a subclass of Throwable
2248+
that indicates serious problems that a reasonable application should not try to
2249+
catch."
2250+
2251+
Under certain circumstances, it is necessary to catch Errors. In those cases,
2252+
catch specific Errors.
2253+
2254+
[source,clojure]
2255+
----
2256+
;; good
2257+
(try (foo)
2258+
(catch ExceptionInfo ex ...)
2259+
(catch AssertionError t ...))
2260+
2261+
;; bad
2262+
(try (foo)
2263+
(catch Throwable t ...))
2264+
----
2265+
22432266
== Macros
22442267

22452268
=== Don't Write a Macro If a Function Will Do [[dont-write-macro-if-fn-will-do]]

0 commit comments

Comments
 (0)