Package org.jf.util

Class ExceptionWithContext

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AnalysisException, DexFileFactory.DexFileNotFoundException, DexFileFactory.MultipleMatchingDexEntriesException, DexFileFactory.UnsupportedFileTypeException, DexFileFactory.UnsupportedOatVersionException, InstructionOffsetMap.InvalidInstructionIndex, InstructionOffsetMap.InvalidInstructionOffset, MethodDefinition.InvalidSwitchPayload, MethodHandleType.InvalidMethodHandleTypeException, ReferenceType.InvalidReferenceTypeException, TryListBuilder.InvalidTryException, UnresolvedClassException

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

    • context

      private StringBuffer context
      non-null; human-oriented context of the exception
  • Constructor Details

    • ExceptionWithContext

      public ExceptionWithContext(String message, Object... formatArgs)
      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(Throwable cause, String message, Object... formatArgs)
      Constructs an instance.
      Parameters:
      cause - null-ok; exception that caused this one
      message - human-oriented message
  • Method Details

    • withContext

      public static ExceptionWithContext withContext(Throwable ex, String str, Object... formatArgs)
      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
    • formatMessage

      private static String formatMessage(String message, Object... formatArgs)
    • 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