LazySeq.sval() nests RuntimeExceptions

Description

When evaluating a LazySeq, if an exception occurs it gets wrapped in a RuntimeException and is thrown. Unfortunately, the logic does not differentiate between a RuntimeException and a checked exception. This has what I believe are two unintended side effects.

  1. If a function throws a RuntimeException, such as an IllegalArgumentException, it gets wrapped in a RuntimeException unnecessarily. So, if I am expecting an IllegalArgumentException (as in a test), I will unexpectedly get a RuntimeException instead.

  2. When evaluating nested lazy sequences, if an error occurs, the root exception is wrapped over and over again as the exception winds its way up the stack. In a recent project, this meant having extremely long stack traces that include a half dozen nested RuntimeExceptions. These just get in the way of getting to the root cause.

Both of these scenarios are illustrated in the attached file.

My proposed solution is fairly simple: Instead of indiscriminately wrapping every exceptions a RuntimeException, simply rethrow any RuntimeException. As a result, any RuntimeException will simply wind its way back up the stack with no wrapping, and checked exceptions will only be wrapped once. This should make debugging Clojure programs slightly easier as the resulting stack trace will not include as much irrelevant information.

Environment

None

Activity

import September 28, 2010 at 10:56 PM

Comment made by: importer

dsg said: [[file:blThXoqYur35a4eJe5afGb]]: Proposed fix

Completed

Details

Assignee

Reporter

Approval

Priority

Fix versions

Created April 8, 2010 at 11:25 PM
Updated December 8, 2010 at 9:50 PM
Resolved December 8, 2010 at 9:50 PM