Clojure

catch receives a RuntimeException rather than the expected checked exception

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.3
  • Fix Version/s: Release 1.4
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Expressions passed to try that trigger the use of clojure.lang.Reflector result in their thrown checked exceptions being wrapped in RuntimeException. As a result, the subsequent set of catches won't switch on the expected checked exception.

Attached: patch for regression test that exposes the problem

(defn- get-exception [expression]
  (try (eval expression)
    nil
    (catch java.lang.Throwable t
      t)))

(deftest catch-receives-checked-exception
  (are [expression expected-exception] (= expected-exception
                                          (type (get-exception expression)))
    "Eh, I'm pretty safe" nil
    '(java.io.FileReader. "CAFEBABEx0/idonotexist") java.io.FileNotFoundException)) ; fails

Clojure ML Thread: https://groups.google.com/forum/#!topic/clojure/I5l1YHVMgkI/discussion
Introduced: https://github.com/clojure/clojure/commit/8fda34e4c77cac079b711da59d5fe49b74605553

  1. checked-exception-regression-test.diff
    11/Oct/11 8:44 PM
    2 kB
    Paul Michael Bauer
  2. CLJ-855_throw_undeclared_checked.patch
    12/Oct/11 9:27 PM
    5 kB
    Herwig Hochleitner
  3. CLJ-855-sneaky-throw.patch
    14/Oct/11 2:34 PM
    22 kB
    Ben Smith-Mannschott
  4. CLJ-855-try-unwraps.patch
    14/Oct/11 12:04 AM
    17 kB
    Ben Smith-Mannschott

Activity

People

Vote (2)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: