Class ExceptionWithContext

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DexException, MutabilityException, ParseException, SimException

public class ExceptionWithContext extends RuntimeException
Exception which carries around structured context.
See Also:
  • Constructor Details

    • ExceptionWithContext

      public ExceptionWithContext(String message)
      Constructs an instance.
      Parameters:
      message - human-oriented message
    • ExceptionWithContext

      public ExceptionWithContext(Throwable cause)
      Constructs an instance.
      Parameters:
      cause - null-ok; exception that caused this one
    • ExceptionWithContext

      public ExceptionWithContext(String message, Throwable cause)
      Constructs an instance.
      Parameters:
      message - human-oriented message
      cause - null-ok; exception that caused this one
  • Method Details

    • withContext

      public static ExceptionWithContext withContext(Throwable ex, String str)
      Augments the given exception with the given context, and return the result. The result is either the given exception if it was an ExceptionWithContext, or a newly-constructed exception if it was not.
      Parameters:
      ex - non-null; the exception to augment
      str - non-null; context to add
      Returns:
      non-null; an appropriate instance
    • printStackTrace

      public void printStackTrace(PrintStream out)
      Overrides:
      printStackTrace in class Throwable
    • printStackTrace

      public void printStackTrace(PrintWriter out)
      Overrides:
      printStackTrace in class Throwable
    • addContext

      public void addContext(String str)
      Adds a line of context to this instance.
      Parameters:
      str - non-null; new context
    • getContext

      public String getContext()
      Gets the context.
      Returns:
      non-null; the context
    • printContext

      public void printContext(PrintStream out)
      Prints the message and context.
      Parameters:
      out - non-null; where to print to
    • printContext

      public void printContext(PrintWriter out)
      Prints the message and context.
      Parameters:
      out - non-null; where to print to