org.apache.logging.log4j.core.impl
Class ThrowableProxy

java.lang.Object
  extended by org.apache.logging.log4j.core.impl.ThrowableProxy
All Implemented Interfaces:
Serializable

public class ThrowableProxy
extends Object
implements Serializable

Wraps a Throwable to add packaging information about each stack trace element.

A proxy is used to represent a throwable that may not exist in a different class loader or JVM. When an application deserializes a ThrowableProxy, the throwable may not be set, but the throwable's information is preserved in other fields of the proxy like the message and stack trace.

TODO: Move this class to org.apache.logging.log4j.core because it is used from LogEvent. TODO: Deserialize: Try to rebuild Throwable if the target exception is in this class loader?

See Also:
Serialized Form

Constructor Summary
ThrowableProxy(Throwable throwable)
          Constructs the wrapper for the Throwable that includes packaging data.
 
Method Summary
 boolean equals(Object obj)
           
 void formatWrapper(StringBuilder sb, ThrowableProxy cause)
          Formats the specified Throwable.
 void formatWrapper(StringBuilder sb, ThrowableProxy cause, List<String> packages)
          Formats the specified Throwable.
 ThrowableProxy getCauseProxy()
           
 String getCauseStackTraceAsString()
          Format the Throwable that is the cause of this Throwable.
 String getCauseStackTraceAsString(List<String> packages)
          Format the Throwable that is the cause of this Throwable.
 int getCommonElementCount()
          Return the number of elements that are being omitted because they are common with the parent Throwable's stack trace.
 ExtendedStackTraceElement[] getExtendedStackTrace()
          Gets the stack trace including packaging information.
 String getExtendedStackTraceAsString()
          Format the stack trace including packaging information.
 String getExtendedStackTraceAsString(List<String> ignorePackages)
          Format the stack trace including packaging information.
 String getLocalizedMessage()
           
 String getMessage()
           
 String getName()
          Return the FQCN of the Throwable.
 StackTraceElement[] getStackTrace()
           
 ThrowableProxy[] getSuppressedProxies()
          Gets proxies for suppressed exceptions.
 String getSuppressedStackTrace()
          Format the suppressed Throwables.
 Throwable getThrowable()
          The throwable or null if this object is deserialized from XML or JSON.
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThrowableProxy

public ThrowableProxy(Throwable throwable)
Constructs the wrapper for the Throwable that includes packaging data.

Parameters:
throwable - The Throwable to wrap, must not be null.
Method Detail

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

formatWrapper

public void formatWrapper(StringBuilder sb,
                          ThrowableProxy cause)
Formats the specified Throwable.

Parameters:
sb - StringBuilder to contain the formatted Throwable.
cause - The Throwable to format.

formatWrapper

public void formatWrapper(StringBuilder sb,
                          ThrowableProxy cause,
                          List<String> packages)
Formats the specified Throwable.

Parameters:
sb - StringBuilder to contain the formatted Throwable.
cause - The Throwable to format.
packages - The List of packages to be suppressed from the trace.

getCauseProxy

public ThrowableProxy getCauseProxy()

getCauseStackTraceAsString

public String getCauseStackTraceAsString()
Format the Throwable that is the cause of this Throwable.

Returns:
The formatted Throwable that caused this Throwable.

getCauseStackTraceAsString

public String getCauseStackTraceAsString(List<String> packages)
Format the Throwable that is the cause of this Throwable.

Parameters:
packages - The List of packages to be suppressed from the trace.
Returns:
The formatted Throwable that caused this Throwable.

getCommonElementCount

public int getCommonElementCount()
Return the number of elements that are being omitted because they are common with the parent Throwable's stack trace.

Returns:
The number of elements omitted from the stack trace.

getExtendedStackTrace

public ExtendedStackTraceElement[] getExtendedStackTrace()
Gets the stack trace including packaging information.

Returns:
The stack trace including packaging information.

getExtendedStackTraceAsString

public String getExtendedStackTraceAsString()
Format the stack trace including packaging information.

Returns:
The formatted stack trace including packaging information.

getExtendedStackTraceAsString

public String getExtendedStackTraceAsString(List<String> ignorePackages)
Format the stack trace including packaging information.

Parameters:
ignorePackages - List of packages to be ignored in the trace.
Returns:
The formatted stack trace including packaging information.

getLocalizedMessage

public String getLocalizedMessage()

getMessage

public String getMessage()

getName

public String getName()
Return the FQCN of the Throwable.

Returns:
The FQCN of the Throwable.

getStackTrace

public StackTraceElement[] getStackTrace()

getSuppressedProxies

public ThrowableProxy[] getSuppressedProxies()
Gets proxies for suppressed exceptions.

Returns:
proxies for suppressed exceptions.

getSuppressedStackTrace

public String getSuppressedStackTrace()
Format the suppressed Throwables.

Returns:
The formatted suppressed Throwables.

getThrowable

public Throwable getThrowable()
The throwable or null if this object is deserialized from XML or JSON.

Returns:
The throwable or null if this object is deserialized from XML or JSON.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 1999-2014 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.