I believe it's now fully general and will be convenient to use for all of our exceptional needs.
The attached text file contains a demo session at the repl showing some of its features.
--Steve
Clojure 1.1.0-alpha-SNAPSHOT
user=> (use 'clojure.contrib.except)
nil
user=> (doc throwf)
-------------------------
clojure.contrib.except/throwf
([& args])
Throws an Exception or Error with an optional message formatted using
clojure.core/format. All arguments are optional:
class? cause? format? format-args*
- class defaults to Exception, if present it must name a kind of
Throwable
- cause defaults to nil, if present it must be a Throwable
- format is a format string for clojure.core/format
- format-args are objects that correspond to format specifiers in
format.
nil
user=> (throwf) ; no args
java.lang.Exception (NO_SOURCE_FILE:0)
user=> (throwf "hi there") ; a simple message
java.lang.Exception: hi there (NO_SOURCE_FILE:0)
user=> (throwf "hi there %s %s" 3 :look) ; a formatted message
java.lang.Exception: hi there 3 :look (NO_SOURCE_FILE:0)
user=> (throwf IllegalAccessException "hi there %s %s" 4 :oh) ; specified class
java.lang.IllegalAccessException: hi there 4 :oh (NO_SOURCE_FILE:0)
user=> (try (throwf "there") (catch Exception e (throwf e "hi"))) ; wrapped
cause
java.lang.Exception: hi (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
java.lang.Exception: hi (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4617)
at clojure.core$eval__4610.invoke(core.clj:1730)
at clojure.main$repl__6453$read_eval_print__6465.invoke(main.clj:178)
at clojure.main$repl__6453.doInvoke(main.clj:195)
at clojure.lang.RestFn.invoke(RestFn.java:426)
at clojure.main$repl_opt__6493.invoke(main.clj:249)
at clojure.main$main__6528.doInvoke(main.clj:336)
at clojure.lang.RestFn.invoke(RestFn.java:402)
at clojure.lang.Var.invoke(Var.java:342)
at clojure.lang.AFn.applyToHelper(AFn.java:171)
at clojure.lang.Var.applyTo(Var.java:463)
at clojure.main.main(main.java:37)
Caused by: java.lang.Exception: hi
at user$eval__141.invoke(NO_SOURCE_FILE:9)
at clojure.lang.Compiler.eval(Compiler.java:4601)
... 11 more
Caused by: java.lang.Exception: there
... 13 more
nil
user=> (doc throw-arg)
-------------------------
clojure.contrib.except/throw-arg
([& args])
Throws an IllegalArgumentException. All arguments are optional:
cause? format? format-args*
- cause defaults to nil, if present it must be a Throwable
- format is a format string for clojure.core/format
- format-args are objects that correspond to format specifiers in
format.
nil
user=> (throw-arg "that was a bad argument")
java.lang.IllegalArgumentException: that was a bad argument (NO_SOURCE_FILE:0)
user=>
smime.p7s
Description: S/MIME cryptographic signature
