[clojure-contrib commit] r934 - condition: add print-stack-trace, fix handling of nil forms in handler-case

0 views
Skip to first unread message

codesite...@google.com

unread,
Jun 11, 2009, 1:57:52 AM6/11/09
to clojure...@googlegroups.com
Author: scgilardi
Date: Wed Jun 10 22:57:21 2009
New Revision: 934

Modified:
trunk/src/clojure/contrib/condition.clj
trunk/src/clojure/contrib/condition/example.clj

Log:
condition: add print-stack-trace, fix handling of nil forms in handler-case

Modified: trunk/src/clojure/contrib/condition.clj
==============================================================================
--- trunk/src/clojure/contrib/condition.clj (original)
+++ trunk/src/clojure/contrib/condition.clj Wed Jun 10 22:57:21 2009
@@ -77,9 +77,9 @@
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 @@
(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))))

Modified: trunk/src/clojure/contrib/condition/example.clj
==============================================================================
--- trunk/src/clojure/contrib/condition/example.clj (original)
+++ trunk/src/clojure/contrib/condition/example.clj Wed Jun 10 22:57:21 2009
@@ -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*))))

Reply all
Reply to author
Forward
0 new messages