aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscgilardi <scgilardi@gmail.com>2009-06-11 05:57:21 +0000
committerscgilardi <scgilardi@gmail.com>2009-06-11 05:57:21 +0000
commited14fb1c4ff5829a7da61a09673006365f5db959 (patch)
tree14e857154bc4a9cc81bf11c288c9bb7fdb93a4fe
parent8711da996ee73bb21b94ec5a28cadc863bd422c1 (diff)
condition: add print-stack-trace, fix handling of nil forms in handler-case
-rw-r--r--src/clojure/contrib/condition.clj15
-rw-r--r--src/clojure/contrib/condition/example.clj3
2 files changed, 16 insertions, 2 deletions
diff --git a/src/clojure/contrib/condition.clj b/src/clojure/contrib/condition.clj
index c396a7a9..c9ffb908 100644
--- a/src/clojure/contrib/condition.clj
+++ b/src/clojure/contrib/condition.clj
@@ -77,9 +77,9 @@ http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5"}
handled and *selector* is bound to to the value returned by dispatch-fn
that matched the handler's key."
[dispatch-fn & body]
- (loop [[form & forms] body
+ (loop [[form & forms :as body] body
m {:code [] :handlers []}]
- (if form
+ (if (seq body)
(recur
forms
(if (and (list? form) (= (first form) 'handle))
@@ -96,3 +96,14 @@ http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5"}
(cond
~@(:handlers m)
:else (raise))))))))
+
+(defn print-stack-trace
+ "Prints the stack trace for a condition"
+ [condition]
+ (printf "condition\n")
+ (doseq [frame (:stack-trace condition)]
+ (printf " at %s.%s(%s:%s)\n"
+ (.getClassName frame)
+ (.getMethodName frame)
+ (.getFileName frame)
+ (.getLineNumber frame))))
diff --git a/src/clojure/contrib/condition/example.clj b/src/clojure/contrib/condition/example.clj
index e437cf6e..04ef7d67 100644
--- a/src/clojure/contrib/condition/example.clj
+++ b/src/clojure/contrib/condition/example.clj
@@ -34,6 +34,8 @@
(handler-case :source
(handler-case :source
+ nil
+ nil
(println (func 8 2))
(println (func -6 17))
;; no handler for ::Args
@@ -42,4 +44,5 @@
(println (func 3 4))
(println (func -5 10))
(handle ::Args
+ (print-stack-trace *condition*)
(printf "Bad argument: %s\n" *condition*))))