java.lang.Object
org.klojang.util.exception.ExceptionOrigin
Provides detailed information about the origin of an exception. Useful for tracing
back an exception to a statement within some code base (e.g. your own). Example:
try { // stuff ... } catch (Exception e) { // Log exception message plus class and line number within the // com.mycompany code base where things flew off the rails logger.error(new ExceptionOrigin(e, "com.mycompany").getDetailedMessage()); }
- See Also:
-
Constructor Summary
ConstructorDescriptionExceptionOrigin
(Throwable exc, String search) Creates a newExceptionOrigin
for the provided exception, searching its stack trace for an element matching the search string. -
Method Summary
Modifier and TypeMethodDescriptionReturns the first stack trace element matching the search string.Returns the class in which the exception occurred ornull
if the exception came without a stack trace.Provides a detailed exception message that includes the class, method and line number of the first statement in the stack trace that matches the search string.Returns the exception wrapped by thisExceptionOrigin
.int
getLine()
Returns the line at which the exception occurred or -1 if the exception came without a stack trace.Returns the method in which the exception occurred ornull
if the exception came without a stack trace.Returns the module in which the exception occurred ornull
if the exception came without a stack trace.boolean
Returnstrue
if the stack trace element found using the search term represents the absolute origin of the exception.toString()
ReturnsgetDetailedMessage()
.
-
Constructor Details
-
ExceptionOrigin
Creates a newExceptionOrigin
for the provided exception, searching its stack trace for an element matching the search string. Matching happens through a simpleString.contains
on the fully-qualified class name.- Parameters:
exc
- the exception to analyzesearch
- any part of the package name or class name that you want the exception to be traced back to.
-
-
Method Details
-
getDetailedMessage
Provides a detailed exception message that includes the class, method and line number of the first statement in the stack trace that matches the search string. Note that this may not be the absolute origin of the exception - the statement from which the exception was thrown. If the search term does happen to hit upon the absolute origin of the exception, the detailed exception message will include a notification to that effect. Otherwise the class, method and line number of the statement that did throw the exception is also included in the detailed exception message.- Returns:
- A detailed exception message
-
toString
ReturnsgetDetailedMessage()
. -
getException
Returns the exception wrapped by thisExceptionOrigin
.- Returns:
- the exception wrapped by this
ExceptionOrigin
-
geStackTraceElement
Returns the first stack trace element matching the search string.- Returns:
- the first stack trace element matching the search string
-
getModule
Returns the module in which the exception occurred ornull
if the exception came without a stack trace.- Returns:
- the module in which the exception occurred or
null
if the exception came without a stack trace
-
getClassName
Returns the class in which the exception occurred ornull
if the exception came without a stack trace.- Returns:
- the class in which the exception occurred or
null
if the exception came without a stack trace
-
getMethod
Returns the method in which the exception occurred ornull
if the exception came without a stack trace.- Returns:
- the method in which the exception occurred or
null
if the exception came without a stack trace
-
getLine
public int getLine()Returns the line at which the exception occurred or -1 if the exception came without a stack trace.- Returns:
- the line at which the exception occurred or -1 if the exception came without a stack trace
-
isAbsoluteOrigin
public boolean isAbsoluteOrigin()Returnstrue
if the stack trace element found using the search term represents the absolute origin of the exception. That is, whether it encapsulates the point at which the exception was thrown.- Returns:
true
if the stack trace element found using the search term represents the absolute origin of the exception
-