StandardExceptionParser

public class StandardExceptionParser extendsObject
implements ExceptionParser

This class will capture the root cause (last in a chain of causes)Throwableand 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 causeThrowable,then checking each StackTraceElementfor a class that is in a package list created bysetIncludedPackages(Context, Collection),starting with the firstStackTraceElement.

TheStringreturned bygetDescription(String, Throwable)will take the form Exception class(@classname:methodname){threadname}.

SeegetBestStackTraceElement(Throwable)andsetIncludedPackages(Context, Collection)for details.

Public Constructor Summary

StandardExceptionParser(Contextcontext,Collection<String> additionalPackages)

Public Method Summary

String
getDescription(StringthreadName,Throwablet)
Return a short description of aThrowablesuitable for reporting to Google Analytics.
void
setIncludedPackages(Contextcontext,Collection<String> additionalPackages)
Sets the list of packages considered relevant to the list of packages in theContext and the list of packages provided in the input parameteradditionalPackages.

Protected Method Summary

StackTraceElement
getBestStackTraceElement(Throwablet)
Return the firstStackTraceElementfound that has a className in any packageName found inincludedPackages.
Throwable
getCause(Throwablet)
Get the root cause of the inputThrowable.
String
getDescription(Throwablecause,StackTraceElementelement,StringthreadName)
Given input of aThrowable,aStackTraceElementand the name of theThread,return aStringdescribing theThrowableand the name of theClassand method where theThrowablehappened.

Inherited Method Summary

Public Constructors

public StandardExceptionParser (Contextcontext,Collection<String> additionalPackages)

Public Methods

public String getDescription (StringthreadName,Throwablet)

Return a short description of aThrowablesuitable for reporting to Google Analytics.

Parameters
threadName the name of theThreadthat got the exception, or null
t theThrowable
Returns
  • the description

public void setIncludedPackages (Contextcontext,Collection<String> additionalPackages)

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

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

Parameters
context anyContextfor the application
additionalPackages a collection of additional package names to add

Protected Methods

protected StackTraceElement getBestStackTraceElement (Throwablet)

Return the firstStackTraceElementfound that has a className in any packageName found inincludedPackages.If none have a className in any packageName found inincludedPackages,return the firstStackTraceElementfound. If theThrowable does not contain anyStackTraceElements, return null.

protected Throwable getCause (Throwablet)

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

Parameters
t the initialThrowable
Returns
  • the root cause

protected String getDescription (Throwablecause,StackTraceElementelement,StringthreadName)

Given input of aThrowable,aStackTraceElementand the name of theThread,return aStringdescribing theThrowableand the name of theClassand method where theThrowablehappened. TheStringreturned will also have the name of the thread appended (as provided in the input parameter threadName).