Class PError

java.lang.Object
org.praxislive.core.Value
org.praxislive.core.types.PError

public final class PError extends Value
An error message, possibly wrapping a Java Exception.
  • Field Details

  • Method Details

    • exceptionType

      @Deprecated public Class<? extends Exception> exceptionType()
      Deprecated.
    • errorType

      public String errorType()
      The error type, usually the simple name of a Java Exception.
      Returns:
      error type
    • message

      public String message()
      The error message.
      Returns:
      error message
    • stackTrace

      public String stackTrace()
      A short form of the stack trace leading to this error, if available. Otherwise an empty String.
      Returns:
      stack trace or empty String.
    • exception

      public Optional<Exception> exception()
      The wrapped exception, if available. Direct access to the exception is only available in the process in which the error was created.
      Returns:
      optional exception
    • toString

      public String toString()
      Description copied from class: Value
      Values must override the default method to return a string representation that is immutable.
      Specified by:
      toString in class Value
      Returns:
      String representation
    • dataMap

      public PMap dataMap()
      The error as a PMap. This is similar to PMap.MapBasedValue except that the map representation of a PError is created lazily. A PError recreated from its PMap representation will not have an Exception reference.
      Returns:
      PError data as a PMap
    • hashCode

      public int hashCode()
      Description copied from class: Value
      Values must override the default hashcode method.
      Specified by:
      hashCode in class Value
      Returns:
      int hashcode
    • equals

      public boolean equals(Object obj)
      Description copied from class: Value
      Values must override the default equals method. This method should only return true if the supplied Object is of the same type as the implementing Value. Values of an unknown type should be coerced before calling this method. This method does not have to guarantee that this.equals(that) == this.toString().equals(that.toString())
      Specified by:
      equals in class Value
      Parameters:
      obj -
      Returns:
      boolean
    • parse

      public static PError parse(String string) throws ValueFormatException
      Parse a String as a PError. This first parses the text as a PMap.
      Parameters:
      string - text representation
      Returns:
      PError instance
      Throws:
      ValueFormatException - if the text cannot be parsed
    • from

      public static Optional<PError> from(Value value)
      Cast or convert the provided value into a PError, wrapped in an Optional. If the value is already a PError, the Optional will wrap the existing value. If the value is not a PError and cannot be converted into one, an empty Optional is returned.
      Parameters:
      value - value
      Returns:
      optional PError
    • of

      public static PError of(Exception ex)
      Create a PError wrapping the given Exception. The message will be taken from the exception, and the error type will be the simple name of the exception's class.
      Parameters:
      ex - exception
      Returns:
      PError instance
    • of

      public static PError of(Exception ex, String msg)
      Create a PError wrapping the given Exception, with a custom message. The exception's message will be ignored. The error type will be the simple name of the exception's class.
      Parameters:
      ex - exception
      msg - message
      Returns:
      PError instance
    • of

      public static PError of(String msg)
      Create a PError of the given message. The error type will be Exception.
      Parameters:
      msg - message
      Returns:
      PError instance
    • of

      public static PError of(Class<? extends Exception> type, String msg)
      Create a PError of the given type and message. The error type will be the simple name of the passed in Exception type.
      Parameters:
      type - error type
      msg - message
      Returns:
      PError instance