Skip to content

Add section warning against catching Throwables #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,29 @@ throw an exception -- throws an exception of a standard type

Favor `with-open` over `finally`.

=== Catching Throwables [[catching-throwables]]

Don't catch `Throwable`. It is a superclass of all Errors and Exceptions in
Java, and as such, it will swallow _all_ possible Errors. As explained by the
Java documentation on the `Error` class, "An Error is a subclass of Throwable
that indicates serious problems that a reasonable application should not try to
catch."

Under certain circumstances, it is necessary to catch Errors. In those cases,
catch specific Errors.

[source,clojure]
----
;; good
(try (foo)
(catch ExceptionInfo ex ...)
(catch AssertionError t ...))

;; bad
(try (foo)
(catch Throwable t ...))
----

== Macros

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