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

Ben Smith-Mannschott made changes -
Field Original Value New Value
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
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

{code:none}
(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
{code}

Clojure ML Thread: https://groups.google.com/forum/#!topic/clojure/I5l1YHVMgkI/discussion
Introduced: https://github.com/clojure/clojure/commit/8fda34e4c77cac079b711da59d5fe49b74605553
Ben Smith-Mannschott made changes -
Attachment 0001-CLJ-855-RFC-solution-using-specific-RTE-subclass-and.patch [ 10383 ]
Herwig Hochleitner made changes -
Paul Michael Bauer made changes -
Waiting On stuart.sierra
Ben Smith-Mannschott made changes -
Attachment 0001-CLJ-855-RFC-solution-using-specific-RTE-subclass-and.patch [ 10383 ]
Ben Smith-Mannschott made changes -
Attachment CLJ-855-try-unwraps.patch [ 10390 ]
Ben Smith-Mannschott made changes -
Attachment CLJ-855-sneaky-throw.patch [ 10395 ]
Ben Smith-Mannschott made changes -
Assignee Ben Smith-Mannschott [ bsmith.occs@gmail.com ]
Patch Code and Test [ 10002 ]
Rich Hickey made changes -
Resolution Completed [ 1 ]
Fix Version/s Backlog [ 10035 ]
Fix Version/s Release 1.4 [ 10040 ]
Approval Ok [ 10007 ]
Status Open [ 1 ] Resolved [ 5 ]
Stuart Halloway made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (2)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: