From 76fb74a4f8d8859b2e551b8aa2e19edc31a440c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Marczyk?= <michal.marczyk@gmail.com>
Date: Thu, 6 Dec 2012 13:20:21 +0100
Subject: [PATCH] CLJ-1120: ex-message, ex-cause

Introduces ex-message and ex-cause functions for dealing with
ExceptionInfo in a platform-independent manner. Actually implemented
and documented to return messages / causes of arbitrary Throwables.
---
 src/clj/clojure/core.clj |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 57400ef..d21e49c 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -4320,6 +4320,24 @@
   (when (instance? IExceptionInfo ex)
     (.getData ^IExceptionInfo ex)))
 
+(defn ex-message
+  "Alpha - subject to change.
+  Returns the message attached to ex if ex is a Throwable.
+  Otherwise returns nil."
+  {:added "1.5"}
+  [ex]
+  (when (instance? Throwable ex)
+    (.getMessage ^Throwable ex)))
+
+(defn ex-cause
+  "Alpha - subject to change.
+  Returns the cause of ex if ex is a Throwable.
+  Otherwise returns nil."
+  {:added "1.5"}
+  [ex]
+  (when (instance? Throwable ex)
+    (.getCause ^Throwable ex)))
+
 (defmacro assert
   "Evaluates expr and throws an exception if it does not evaluate to
   logical true."
-- 
1.7.1

