sci icon indicating copy to clipboard operation
sci copied to clipboard

Rethrowing exception in catch block loses original line number info

Open Cnly opened this issue 4 years ago • 0 comments

version

This is with babashka 0.7.0 so should be https://github.com/babashka/sci/tree/573ee0e2f2ecdfc30f9f4b0d306626cacd6d3f06.

platform

Mac, binary

problem

If an exception is caught and rethrown in a catch block, the location of the exception will be that of the form rethrowing it, and the actual (previous) line number won't be in the stack trace.

repro

e.clj:

(ns e)

(defn throw-err []  ;; Line 3
  (throw (RuntimeException. "oops")))

(defn -main []  ;; Line 6
  (try
    (throw-err)
    (catch Exception e
      (throw e))))  ;; Line 10

(when (= (System/getProperty "babashka.file") *file*)
  (-main))  ;; Line 13

Execution using bb:

$ bb ./e.clj
----- Error --------------------------------------------------------------------
Type:     java.lang.RuntimeException
Message:  oops
Location: /path/to/project/./e.clj:10:7

----- Context ------------------------------------------------------------------
 6: (defn -main []
 7:   (try
 8:     (throw-err)
 9:     (catch Exception e
10:       (throw e))))
          ^--- oops
11:
12: (when (= (System/getProperty "babashka.file") *file*)
13:   (-main))

----- Stack trace --------------------------------------------------------------
e/-main - /path/to/project/./e.clj:6:1
e       - /path/to/project/./e.clj:13:3

expected behavior

Running with clojure:

$ clj -Sdeps '{:paths ["."]}' -M -m e
Execution error at e/throw-err (e.clj:3).
oops

Full report at:
/var/folders/fw/4qtvtzs51h13t2hhgynxb3l40000gn/T/clojure-10461153020420980203.edn

Cnly avatar Dec 12 '21 08:12 Cnly