Class RuleError

  • All Implemented Interfaces:
    java.io.Serializable

    public final class RuleError
    extends java.lang.RuntimeException
    An exception that can be thrown when a rule-set is invalid.

    Used for providing meaningful contextual information when an invalid rule-set is encountered.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  RuleError.Evaluator<T>  
    • Constructor Summary

      Constructors 
      Constructor Description
      RuleError​(SourceException root)
      Constructs a new RuleError from the source exception.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void context​(java.lang.String message, java.lang.Runnable runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      static void context​(java.lang.String message, FromSourceLocation sourceLocation, java.lang.Runnable runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      static <T> T context​(java.lang.String message, FromSourceLocation sourceLocation, RuleError.Evaluator<T> runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      static <T> T context​(java.lang.String message, RuleError.Evaluator<T> runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      java.lang.String toString()  
      RuleError withContext​(java.lang.String context, SourceLocation location)
      Sets a piece of context on this error.
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RuleError

        public RuleError​(SourceException root)
        Constructs a new RuleError from the source exception.
        Parameters:
        root - the exception this rule error is based on.
    • Method Detail

      • context

        public static void context​(java.lang.String message,
                                   java.lang.Runnable runnable)
        Evaluates the runnable and creates a RuleError with the provided context if there's an error.
        Parameters:
        message - a message representing the context for this runnable statement's evaluation.
        runnable - a runnable to evaluate a statement in the current context.
      • context

        public static <T> T context​(java.lang.String message,
                                    RuleError.Evaluator<T> runnable)
                             throws RuleError
        Evaluates the runnable and creates a RuleError with the provided context if there's an error.
        Type Parameters:
        T - the type of the value returned by the runnable.
        Parameters:
        message - a message representing the context for this runnable statement's evaluation.
        runnable - a runnable to evaluate a statement in the current context.
        Returns:
        the value returned by the runnable.
        Throws:
        RuleError - when the rule being evaluated in the context fails.
      • context

        public static void context​(java.lang.String message,
                                   FromSourceLocation sourceLocation,
                                   java.lang.Runnable runnable)
        Evaluates the runnable and creates a RuleError with the provided context if there's an error.
        Parameters:
        message - a message representing the context for this runnable statement's evaluation.
        sourceLocation - the source location for this runnable statement's evaluation.
        runnable - a runnable to evaluate a statement in the current context.
      • context

        public static <T> T context​(java.lang.String message,
                                    FromSourceLocation sourceLocation,
                                    RuleError.Evaluator<T> runnable)
                             throws RuleError
        Evaluates the runnable and creates a RuleError with the provided context if there's an error.
        Type Parameters:
        T - the type of the value returned by the runnable.
        Parameters:
        message - a message representing the context for this runnable statement's evaluation.
        sourceLocation - the source location for this runnable statement's evaluation.
        runnable - a runnable to evaluate a statement in the current context.
        Returns:
        the value returned by the runnable.
        Throws:
        RuleError - when the rule being evaluated in the context fails.
      • withContext

        public RuleError withContext​(java.lang.String context,
                                     SourceLocation location)
        Sets a piece of context on this error.
        Parameters:
        context - the context to add to the error.
        location - the source location of the context being added.
        Returns:
        returns this error with the added context.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Throwable