concept exception in category clojure

This is an excerpt from Manning's book Clojure: The Essential Reference.
Core support namespaces integrate core with additional functionalities on top of those already present. clojure.stringis possibly the best example. Core already contains “str” but any other useful string functionalities have been moved out into theclojure.stringnamespace.clojure.templatecontains a few helpers for macro creation.clojure.setis about the "set" data structure.clojure.pprintcontains formatters for almost all Clojure data types so they can print in a nice, human-readable form. Finallyclojure.stacktracecontains functions to manipulate exceptions and their formatting.
(-> vzip zip/down zip/rightmost (zip/insert-left 'INS) zip/up zip/node) ; #1 ;; [[1 2] [3 4 [5 10 [11 12]]] INS [13 14]] (-> vzip zip/down zip/rightmost (zip/insert-right 'INS) zip/up zip/node) ; #2 ;; [[1 2] [3 4 [5 10 [11 12]]] [13 14] INS] (-> vzip zip/down zip/rightmost (zip/insert-child 'INS) zip/up zip/node) ; #3 ;; [[1 2] [3 4 [5 10 [11 12]]] [INS 13 14]] (-> vzip zip/down zip/rightmost zip/down (zip/insert-child 'INS)) ; #4 ;; Exception called children on a leaf node
finallyis a specialcatchclause that is always evaluated, even when there is no exceptional condition. Thetry-finallypattern is pretty popular to handle resources that must always be released, even in case of exception. with-open is an excellent example of this behavior and it usesfinallyto make sure any resource open as part of the bindings is correctly closed. Similarly locking usesfinallyto always release the lock after executing a critical region. In the following example, we build a simplifiedwith-opento deal withjava.io.Readerobjects only:

This is an excerpt from Manning's book The Joy of Clojure, Second Edition.
The mechanism to throw an exception is fairly straightforward:
(throw (Exception. "I done throwed")) ;=> java.lang.Exception: I done throwed ...The syntax for catching exceptions in Clojure is similar to that of Java:
(defn throw-catch [f] [(try (f) (catch ArithmeticException e "No dividing by zero!") (catch Exception e (str "You are so bad " (.getMessage e))) (finally (println "returning... ")))]) (throw-catch #(/ 10 5)) ; returning... ;=> [2] (throw-catch #(/ 10 0)) ; returning... ;=> ["No dividing by zero!"] (throw-catch #(throw (Exception. "Crybaby"))) ; returning... ;=> ["You are so bad Crybaby"]The major difference between how Java and Clojure handle exceptions is that Clojure doesn’t adhere to checked-exception requirements. The ClojureScript catch form looks similar except for the need to use js to catch core error types, as shown next:
We’ll attempt to constrain ourselves to the generalities of exception handling in this section. If you desire information on deciphering exception messages, we talk about that in section 3.4. If you’re curious about the effects of exceptions on continuation-passing style, then refer to section 7.3.4. We discuss the behavior of Clojure when it attempts to supplant numerical inaccuracies by throwing exceptions in section 4.1.3. If you want to learn about the interplay between exceptions and Clojure’s reference types, such matters can be found throughout chapter 11. Finally, if you have no idea what an exception is, we discuss the basics in section 2.9.
Nothing is preventing the exception from being thrown at runtime, but because we know pairs requires an even number of arguments, we instead prefer to fail as early as possible—at compilation time. This difference is clearly demonstrated by repeating the preceding test in a function definition:
(fn [] (pairs 1 2 3)) ; java.lang.Exception: pairs requires an even number of argsA runtime exception wouldn’t have been thrown until this function was called, but because the pairs macro threw an exception at compile time, users are notified of their error immediately. Although it’s powerful, you should always try to balance the benefits of compile-time error checking with macros and the advantages that implementing as a function provides (the use in higher-order functions, apply, and so on).
Figure 12.9. There are two ways to handle errors in Clojure. The typical way is to let exceptions flow from the inner forms to the outer. The other way, discussed in section 17.4, uses dynamic bindings to reach into the inner forms to handle errors immediately.
![]()
The behavior of Clojure’s exception features directly spawns from the JVM enforcing the promulgation of checked exceptions. Virtuous or not in the context of Java development, checked exceptions are antithetical to closures and higher-order functions. Checked exceptions require not only that the thrower and the party responsible for handling them should declare interest, but also that every intermediary is forced to participate. These intermediaries don’t have to actively throw or handle exceptions occurring within, but they must declare that they’ll be “passing through.” Therefore, by including the call to a Java method throwing a checked exception within a closure, Clojure has two possible alternatives: