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

Implement ex-message, ex-data and ex-cause #189

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions compiler+runtime/src/jank/clojure/core.jank
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,29 @@
(def ex-info
"Create an instance of ExceptionInfo, a RuntimeException subclass
that carries a map of additional data."
; TODO: Arity 3
(fn* ex-info [msg map]
{:error msg
:data map}))
(fn* ex-info
([msg map]
{:error msg
:data map})
([msg map cause]
{:error msg
:data map
:cause cause})))

(def ex-message
"Returns the message attached to ex if ex is a Throwable.
Otherwise returns nil."
:error)

(def ex-data
"Returns exception data (a map) if ex is an IExceptionInfo.
Otherwise returns nil."
:data)

(def ex-cause
"Returns the cause of ex if ex is a Throwable.
Otherwise returns nil."
:cause)

; Relations.
;; Miscellaneous.
Expand Down Expand Up @@ -5698,30 +5717,6 @@
;; (drop-while #(= class-name (.getClassName ^StackTraceElement %1)) tr))))))
(throw "TODO: port"))

(defn ex-data
"Returns exception data (a map) if ex is an IExceptionInfo.
Otherwise returns nil."
[ex]
;; (when (instance? IExceptionInfo ex)
;; (.getData ^IExceptionInfo ex))
(throw "TODO: port"))

(defn ex-message
"Returns the message attached to ex if ex is a Throwable.
Otherwise returns nil."
[ex]
;; (when (instance? Throwable ex)
;; (.getMessage Throwable ex))
(throw "TODO: port"))

(defn ex-cause
"Returns the cause of ex if ex is a Throwable.
Otherwise returns nil."
[ex]
;; (when (instance? Throwable ex)
;; (.getCause ^Throwable ex))
(throw "TODO: port"))

(defn test
"test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception"
Expand Down
Loading