erp12.fijit.try
Idiomatic Clojure wrapper around the scala.util.Try
abstraction.
failure?
(failure? try)
Checks if the try
is a failure. Returns false
if try
is not an instance of scala.Try
.
get
macro
(get try)
(get try or-else)
Returns the value from try
if it is a Success
or throws the exception if it is a Failure
.
If an or-else
form is provided, it will be evaluated in the event the try
is a failure instead of throwing the exception. This can be used to recover from failure or to throw a better error.
Example:
(defn my-div
[n d]
(get (scala-try (/ n d))
(throw (ex-info "Failed division!" {:numerator n :denominator d}))))
(my-div 3 0)
; => clojure.lang.ExceptionInfo: Failed division! {:numerator 3, :denominator 0}
scala-try
macro
(scala-try form)
success?
(success? try)
Checks if the try
is a success. Returns false
if try
is not an instance of scala.Try
.