Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrowing exception in catch block loses original line number info #654

Open
Cnly opened this issue Dec 12, 2021 · 0 comments
Open

Rethrowing exception in catch block loses original line number info #654

Cnly opened this issue Dec 12, 2021 · 0 comments

Comments

@Cnly
Copy link

Cnly commented Dec 12, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant