Class RuleExecutionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.brantunger.unruly.api.exception.UnrulyException
io.github.brantunger.unruly.api.exception.RuleExecutionException
- All Implemented Interfaces:
Serializable
Thrown by
run() when a run fails: because a rule's condition or action failed, or because something outside
any rule did.
getRuleName() and getExpressionKind() name the rule and the expression when a condition or action
threw, a condition evaluated to something other than a Boolean, an action returned null, or a
property an action returned couldn't be set on the output. A fatal Error a listener's
beforeEvaluate or beforeExecute callback threw names the rule but no expression. Both are
null for a failure that belongs to no rule:
- the run was interrupted, or passed its deadline, while it waited for a compiled copy of the rules, or while it read them again after a reload, or a close of the engine, closed the list it had read;
- the run was stopped between rules, or when a condition or action returned, or threw something with no
Erroranywhere in its cause chain, nor one suppressed on it at any depth, once the run had to stop, because its thread was interrupted or it passed its deadline; the cause is then anInterruptedExceptionor aTimeoutException. AnInterruptedExceptionin the cause chain of what it threw, or suppressed there, sets the interrupt status again first, so such a throw stops the run as interrupted. One that threw something with anErrorin its cause chain, or suppressed on it at any depth, is that rule's own failure instead, so bothgetRuleName()andgetExpressionKind()are set and the cause is what the expression threw; - more than one rule matched on a unique-match engine, which the message names;
- the output supplier threw or returned
null; - a language threw or returned
nullwhen it created a session for the run; - a fatal
Errorleft the run from the output supplier, from a language's check of a fact name, or from a listener'sbeforeRun,afterEvaluateorafterExecutecallback: thenrun()rethrows the error itself, and this exception, which carries it, goes toRuleListener.onRunError(io.github.brantunger.unruly.api.RunContext, java.lang.RuntimeException). One fromafterRunis rethrown with no exception and no callback.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRuleExecutionException(@Nullable String message) Constructs a new exception with the specified detail message.RuleExecutionException(@Nullable String message, @Nullable Throwable cause) Constructs a new exception with the specified detail message and cause.RuleExecutionException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName) Constructs a new exception with the specified detail message, cause and the name of the rule that failed.RuleExecutionException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName, @Nullable ExpressionKind expressionKind) Constructs a new exception for one rule's condition or action. -
Method Summary
Modifier and TypeMethodDescription@Nullable ExpressionKindReturns whether the rule's condition or its action failed.@Nullable StringReturns the name of the rule that failed, asRule.getRuleName()returns it.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
RuleExecutionException
Constructs a new exception with the specified detail message.- Parameters:
message- The detail message
-
RuleExecutionException
Constructs a new exception with the specified detail message and cause.- Parameters:
message- The detail messagecause- The cause
-
RuleExecutionException
public RuleExecutionException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName) Constructs a new exception with the specified detail message, cause and the name of the rule that failed.- Parameters:
message- The detail messagecause- The causeruleName- The name of the rule that failed, ornullif the failure isn't about one rule or the rule has no name
-
RuleExecutionException
public RuleExecutionException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName, @Nullable ExpressionKind expressionKind) Constructs a new exception for one rule's condition or action.- Parameters:
message- The detail messagecause- The causeruleName- The name of the rule that failed, ornullif the failure isn't about one rule or the rule has no nameexpressionKind- Whether the condition or the action failed, ornullif neither did
-
-
Method Details
-
getRuleName
Returns the name of the rule that failed, asRule.getRuleName()returns it. Unlike the message, it isn't escaped or shortened, so it can be used to look the rule up.- Returns:
- The rule's name, or
nullif the failure isn't about one rule (for example the output supplier failed, or the run was stopped)
-
getExpressionKind
Returns whether the rule's condition or its action failed.- Returns:
- The kind of expression, or
nullif the failure isn't about a condition or an action, for example a listener or the output supplier failed
-