Since version 10 (at least 10.0.2 but I think 10.0.0) there is Failure
and since version 10.2 there is also FailureQ
. As often the documentation is somewhat vague and says "Failure is generated by Interpreter and related functions.".
To me it looks like Failure
is not more than a symbol which can be used as the head of an expression in a return value or an argument to Throw
which indicates that something went wrong. A Failure
expressions is expected to have two arguments, the first being a tag to be able to match against, the second an association as a second argument which can hold additional information about what went wrong. That is very much what an Exception object in other languages would contain and has obvious applications.
The question is whether it would be a good idea to rely on these symbols for my own code or whether it is more safe to run my own "exceptions" package. I currently don't see any disadvantage of just using Failure
in that way which would save me from providing a new symbol in an additional package which creates dependencies and I could also take advantage of an already defined FailureQ
and - less important but nice to have - formatting of these failure-expressions.
Any thoughts and experience out there? Any recommendations from WRI known to be published anywhere?
FailureQ
I think compatibility is a good point to have in mind, but 10.2 would be good enough for my current purpose and as you suggest would be easy enough to provide for versions < 10.2.... $\endgroup$$Failed
and some that returnedFailure
. I would have needed to provide a very clear way for users to test for failure. For v10.0 compatibility I would have had to provide a FailureQ alternative that would be redundant for 10.2. I thought that doing this is too confusing and not user friendly enough. It wasn't a technical reason why I didn't use Failure, it was more about the user experience. $\endgroup$FailureQ
.Failure
is nicer than$Failed
. I do wish WRI made a push to unify the multitude of ways of error reporting/handling. $\endgroup$