Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Message key catalog
# Matches a RuntimeException followed immediately by an IllegalStateException
# whose message property is "hello". When found, the key "noDice" is
# looked up in the ResourceBundle identified by com.edugility.throwables.Bundle.
# The resulting message, if found, is run through MVEL's templating engine first,
# then through java.text.MessageFormat, then through java.util.Formatter.
java.lang.RuntimeException.../java.lang.IllegalStateException(message == "hello")
--
com.edugility.throwables.Bundle#noDice
# If the prior test didn't match, then this one gets invoked. Entries in
# message key catalogs like this are processed sequentially until a match
# occurs.
#
# This test matches a SQLException (and not a subclass) (storing it as a backreference
# under the key 1) followed by any number of Throwables and in a chain
# terminated with a java.lang.Exception instance (and not a subclass).
# If it matches, then the text under the "--" is used as the message, and is
# interpreted as a MessageFormat. Argument #0 will be the throwable that
# caused the pattern to match. Argument #1 will be the backreference. In
# this case it's the same thing.
java.sql.SQLException[1]/**/java.lang.Exception
--
A key
goes here {1}
# If neither of those tests matched, then this block will get invoked. This one
# matches any chain that terminates in an Exception or subclass (so no Errors).
# If it matches, then the MVEL expression in @{} is evaluated, with "this" set
# to the Throwable that matched.
**/java.lang.Exception... # and a comment here
--
This is the default message: @{this.toString()}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment