diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/condition.clj | 15 | ||||
-rw-r--r-- | src/clojure/contrib/condition/example.clj | 3 |
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*)))) |