Package com.android.dex.util
Class ExceptionWithContext
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.android.dex.util.ExceptionWithContext
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DexException
public class ExceptionWithContext extends RuntimeException
Exception which carries around structured context.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExceptionWithContext(String message)Constructs an instance.ExceptionWithContext(String message, Throwable cause)Constructs an instance.ExceptionWithContext(Throwable cause)Constructs an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContext(String str)Adds a line of context to this instance.StringgetContext()Gets the context.voidprintContext(PrintStream out)Prints the message and context.voidprintContext(PrintWriter out)Prints the message and context.voidprintStackTrace(PrintStream out)Writes a printable representation of thisThrowable's stack trace to the given print stream.voidprintStackTrace(PrintWriter out)Writes a printable representation of thisThrowable's stack trace to the specified print writer.static ExceptionWithContextwithContext(Throwable ex, String str)Augments the given exception with the given context, and return the result.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
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
-
-
Method Detail
-
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 anExceptionWithContext, or a newly-constructed exception if it was not.- Parameters:
ex-non-null;the exception to augmentstr-non-null;context to add- Returns:
non-null;an appropriate instance
-
printStackTrace
public void printStackTrace(PrintStream out)
Writes a printable representation of thisThrowable's stack trace to the given print stream. If theThrowablecontains acause, the method will be invoked recursively for the nestedThrowable.- Overrides:
printStackTracein classThrowable
-
printStackTrace
public void printStackTrace(PrintWriter out)
Writes a printable representation of thisThrowable's stack trace to the specified print writer. If theThrowablecontains acause, the method will be invoked recursively for the nestedThrowable.- Overrides:
printStackTracein classThrowable- Parameters:
out- the writer to write the stack trace on.
-
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
-
-