package com.walker.infrastructure.core;
|
|
public class NestedCheckedException extends Exception {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
public NestedCheckedException(String msg){
|
super(msg);
|
}
|
|
public NestedCheckedException(String msg, Throwable cause){
|
super(msg, cause);
|
}
|
|
public String getMessage(){
|
return NestedExceptionUtils.buildMessage(super.getMessage(), getCause());
|
}
|
|
public Throwable getRootCause(){
|
Throwable rootCause = null;
|
for(Throwable cause = getCause(); cause != null && cause != rootCause; cause = cause.getCause())
|
rootCause = cause;
|
return rootCause;
|
}
|
|
public Throwable getMostSpecificCause(){
|
Throwable rootCause = getRootCause();
|
return ((Throwable)(rootCause == null ? this : rootCause));
|
}
|
|
public boolean contains(Class<?> exType){
|
if(exType == null)
|
return false;
|
if(exType.isInstance(this))
|
return true;
|
Throwable cause = getCause();
|
if(cause == this)
|
return false;
|
if(cause instanceof NestedCheckedException)
|
return ((NestedCheckedException)cause).contains(exType);
|
do
|
{
|
if(cause == null)
|
break;
|
if(exType.isInstance(cause))
|
return true;
|
if(cause.getCause() == cause)
|
break;
|
cause = cause.getCause();
|
} while(true);
|
return false;
|
}
|
}
|