public class StandardExceptionParser extends Object
implements ExceptionParser

This class will capture the root cause (last in a chain of causes) Throwable and report the exception type, class name, method name and thread name.

This class will attempt to report a class and method name that is relevant to the application if at all possible. It does this by finding the root cause Throwable, then checking each StackTraceElement for a class that is in a package list created by setIncludedPackages(Context, Collection), starting with the first StackTraceElement.

The String returned by getDescription(String, Throwable) will take on the form Exception class(@classname:methodname){threadname}.

See getBestStackTraceElement(Throwable) and setIncludedPackages(Context, Collection) for details.

Public Constructor Summary

StandardExceptionParser(Context context, Collection<String> additionalPackages)

Public Method Summary

setIncludedPackages(Context context, Collection<String> additionalPackages)

Protected Method Summary

getDescription(Throwable cause, StackTraceElement element, String threadName)

Public Constructors

public StandardExceptionParser (Context context, Collection<String> additionalPackages)

Public Methods

public String getDescription (String threadName, Throwable t)

Return a short description of a Throwable suitable for reporting to Google Analytics.

threadName the name of the Thread that got the exception, or null
t the Throwable
  • the description

public void setIncludedPackages (Context context, Collection<String> additionalPackages)

Sets the list of packages considered relevant to the list of packages in the Context and the list of packages provided in the input parameter additionalPackages. Either parameter can be null.

Any package names stored from a previous call to this method will be cleared.

context any Context for the application
additionalPackages a collection of additional package names to add

Protected Methods

protected StackTraceElement getBestStackTraceElement (Throwable t)

Return the first StackTraceElement found that has a className in any packageName found in includedPackages. If none have a className in any packageName found in includedPackages, return the first StackTraceElement found. If the Throwable does not contain any StackTraceElements, return null.

protected Throwable getCause (Throwable t)

Get the root cause of the input Throwable. This method chains through each cause of the original input and returns the last cause in the chain.

t the initial Throwable
  • the root cause

protected String getDescription (Throwable cause, StackTraceElement element, String threadName)

Given input of a Throwable, a StackTraceElement and the name of the Thread, return a String describing the Throwable and the name of the Class and method where the Throwable happened. The String returned will also have the name of the thread appended (as provided in the input parameter threadName.