本文整理汇总了Java中org.apache.commons.lang.exception.ExceptionUtils.indexOfType方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils.indexOfType方法的具体用法?Java ExceptionUtils.indexOfType怎么用?Java ExceptionUtils.indexOfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.exception.ExceptionUtils
的用法示例。
在下文中一共展示了ExceptionUtils.indexOfType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isCausedByTimeoutException
import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
* <p>Checks if the throwable was caused by timeout exception.</p>
* <b>This method has been tested for Oracle and MySQL only and might not work
* for other DB engines.</b>
*
* @param throwable to check
* @return true if the throwable is caused by a timeout, false otherwise
*/
public boolean isCausedByTimeoutException(Throwable throwable) {
// Valid test for Oracle timeout exception and some (not all!) MySQL
// exceptions.
if (ExceptionUtils.indexOfType(throwable, SQLTimeoutException.class) != -1) {
return true;
}
// MySQL database has two timeout exceptions in two packages. One of them
// doesn't extend SQLTimeoutException but only SQLException. It is therefore
// necessary to do ugly name check...
for (Throwable causeThrowable : ExceptionUtils.getThrowables(throwable)) {
if (MYSQL_TIMEOUT_EXCEPTION_NAME.equals(causeThrowable.getClass().getSimpleName())) {
return true;
}
}
return false;
}
示例2: handleOnTimerException
import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
protected void handleOnTimerException(RuntimeException e) {
int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
//noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
}
throw e;
}
示例3: handleTimerException
import org.apache.commons.lang.exception.ExceptionUtils; //导入方法依赖的package包/类
protected void handleTimerException(RuntimeException ex) {
if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) {
// If a ConnectException occurred, just log it and ignore
log.warn("onTimer error: " + ex.getMessage());
} else {
// Otherwise throw the exception, but first search for NoUserSessionException in chain,
// if found - stop the timer
int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
//noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
}
throw ex;
}
}