diff options
author | scgilardi <scgilardi@gmail.com> | 2009-06-16 04:12:47 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2009-06-16 04:12:47 +0000 |
commit | 443409f56420f3dc7972131c34c189e63d28fdcb (patch) | |
tree | 02fb2a9a12639f8462d43ae7d68fc74d697eba0c /src/clojure/contrib/condition/example.clj | |
parent | a69831f5c84f23f5159448fe2ec0acb633cacf7c (diff) |
condition: refinements
Diffstat (limited to 'src/clojure/contrib/condition/example.clj')
-rw-r--r-- | src/clojure/contrib/condition/example.clj | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/clojure/contrib/condition/example.clj b/src/clojure/contrib/condition/example.clj index 36d7b36f..5a7d72ef 100644 --- a/src/clojure/contrib/condition/example.clj +++ b/src/clojure/contrib/condition/example.clj @@ -12,28 +12,31 @@ ;; Created 09 June 2009 (ns clojure.contrib.condition.example - (:use clojure.contrib.condition)) + (:use (clojure.contrib + [condition + :only (handler-case print-stack-trace raise *condition*)]))) (defn func [x y] - (if (neg? x) - (raise :reason :illegal-argument :arg 'x :value x :message "cannot be negative") - (+ x y))) + "Raises an exception if x is negative" + (when (neg? x) + (raise :type :illegal-argument :arg 'x :value x)) + (+ x y)) (defn main [] ;; simple handler - (handler-case :reason + (handler-case :type (println (func 3 4)) (println (func -5 10)) (handle :illegal-argument - (print-stack-trace *condition*)) + (print-stack-trace *condition*)) (println 3)) ;; multiple handlers - (handler-case :reason + (handler-case :type (println (func 4 1)) (println (func -3 22)) (handle :overflow @@ -43,8 +46,8 @@ ;; nested handlers - (handler-case :reason - (handler-case :reason + (handler-case :type + (handler-case :type nil nil (println 1) |