热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.commons.lang.exception.ExceptionUtils.getRootCause()方法的使用及代码示例

本文整理了Java中org.apache.commons.lang.exception.ExceptionUtils.getRootCause()方法的一些代码示例,展

本文整理了Java中org.apache.commons.lang.exception.ExceptionUtils.getRootCause()方法的一些代码示例,展示了ExceptionUtils.getRootCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionUtils.getRootCause()方法的具体详情如下:
包路径:org.apache.commons.lang.exception.ExceptionUtils
类名称:ExceptionUtils
方法名:getRootCause

ExceptionUtils.getRootCause介绍

[英]Introspects the Throwable to obtain the root cause.

This method walks through the exception chain to the last element, "root" of the tree, using #getCause(Throwable), and returns that exception.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops. If the throwable parameter has a cause of itself, then null will be returned. If the throwable parameter cause chain loops, the last element in the chain before the loop is returned.
[中]内省Throwable以获取根本原因。
此方法使用#getCause(Throwable)遍历异常链,找到树的最后一个元素“root”,并返回该异常。
从版本2.2开始,此方法处理可能导致无限循环的递归原因结构。如果throwable参数本身有原因,那么将返回null。如果throwable参数导致链循环,则返回循环之前链中的最后一个元素。

代码示例

代码示例来源:origin: apache/incubator-gobblin

private static Throwable getRootCause(Throwable t) {
Throwable rootCause = ExceptionUtils.getRootCause(t);
if (rootCause == null) {
rootCause = t;
}
return rootCause;
}
}

代码示例来源:origin: commons-lang/commons-lang

/**
* Gets a short message summarising the root cause exception.
*


* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getRootCauseMessage(Throwable th) {
Throwable root = ExceptionUtils.getRootCause(th);
root = (root == null ? th : root);
return getMessage(root);
}

代码示例来源:origin: apache/zeppelin

private String getJobExceptionStack(Throwable e) {
if (e == null) {
return "";
}
Throwable cause = ExceptionUtils.getRootCause(e);
if (cause != null) {
return ExceptionUtils.getFullStackTrace(cause);
} else {
return ExceptionUtils.getFullStackTrace(e);
}
}

代码示例来源:origin: alibaba/yugong

private boolean processException(Throwable e, int i) {
if (!(ExceptionUtils.getRootCause(e) instanceof InterruptedException)) {
logger.error("retry {} ,something error happened. caused by {}",
(i + 1),
ExceptionUtils.getFullStackTrace(e));
try {
alarmService.sendAlarm(new AlarmMessage(ExceptionUtils.getFullStackTrace(e), alarmReceiver));
} catch (Throwable e1) {
logger.error("send alarm failed. ", e1);
}
try {
Thread.sleep(retryInterval);
} catch (InterruptedException e1) {
exception = new YuGongException(e1);
Thread.currentThread().interrupt();
return true;
}
} else {
// interrupt事件,响应退出
return true;
}
return false;
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Override
public GatewayFilter apply(Config config) {
return (exchange, chain) -> {
ServerWebExchange filteredExchange = ofNullable((Throwable) exchange
.getAttribute(HYSTRIX_EXECUTION_EXCEPTION_ATTR))
.map(executionException -> {
ServerHttpRequest.Builder requestBuilder = exchange.getRequest().mutate();
requestBuilder.header(config.executionExceptionTypeHeaderName, executionException.getClass().getName());
requestBuilder.header(config.executionExceptionMessageHeaderName, executionException.getMessage());
ofNullable(getRootCause(executionException)).ifPresent(rootCause -> {
requestBuilder.header(config.rootCauseExceptionTypeHeaderName, rootCause.getClass().getName());
requestBuilder.header(config.rootCauseExceptionMessageHeaderName, rootCause.getMessage());
});
return exchange.mutate().request(requestBuilder.build()).build();
}).orElse(exchange);
return chain.filter(filteredExchange);
};
}

代码示例来源:origin: Alluxio/alluxio

startServing(" (gained leadership)", " (lost leadership)");
} catch (Throwable t) {
Throwable root = ExceptionUtils.getRootCause(t);
if ((root != null && (root instanceof InterruptedException)) || Thread.interrupted()) {
return;

代码示例来源:origin: apache/nifi

nrOfRows += 1;
} catch (DataFileWriter.AppendWriteException awe) {
Throwable rootCause = ExceptionUtils.getRootCause(awe);
if(rootCause instanceof UnresolvedUnionException) {
UnresolvedUnionException uue = (UnresolvedUnionException) rootCause;

代码示例来源:origin: alibaba/yugong

} else if (ExceptionUtils.getRootCause(exception) instanceof InterruptedException) {
progressTracer.update(context.getTableMeta().getFullName(), ProgressStatus.FAILED);
logger.info("table[{}] is interrpt ,current status:{} !", context.getTableMeta()

代码示例来源:origin: apache/tinkerpop

@Override
public void close() throws Exception {
if (!closed) {
final RequestMessage msg = RequestMessage.build(Tokens.OPS_CLOSE)
.addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffect)
.addArg(Tokens.ARGS_HOST, host)
.processor("traversal").create();
try {
client.submitAsync(msg).get();
closed = true;
} catch (Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
throw new RuntimeException("Error on closing side effects", null == root ? ex : root);
}
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJdbcWrongKey() throws Exception {
try {
testResult(db, "CALL apoc.load.jdbc('derbyy','PERSON')", (r) -> {});
} catch (QueryExecutionException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof RuntimeException);
assertEquals("No apoc.jdbc.derbyy.url url specified", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testExportGraphGraphMLQueryGephiWithStringCaption() throws Exception {
File output = new File(directory, "query.graphml");
try {
TestUtil.testCall(db, "call apoc.export.graphml.query('MATCH p=()-[r]->() RETURN p limit 1000',{file},{useTypes:true, format: 'gephi', caption: 'name'}) ", map("file", output.getAbsolutePath()),
(r) -> {});
} catch (QueryExecutionException e) {
Throwable except = ExceptionUtils.getRootCause(e);
TestCase.assertTrue(except instanceof RuntimeException);
assertEquals("Only array of Strings are allowed!", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testImportGraphMLWithNoImportConfig() throws Exception {
File output = new File(directory, "all.graphml");
try {
TestUtil.testCall(db, "CALL apoc.import.graphml({file},{readLabels:true})", map("file", output.getAbsolutePath()), (r) -> assertResults(output, r, "database"));
} catch (QueryExecutionException e) {
Throwable except = ExceptionUtils.getRootCause(e);
TestCase.assertTrue(except instanceof RuntimeException);
assertEquals("Import from files not enabled, please set apoc.import.file.enabled=true in your neo4j.conf", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testExportGraphGraphMLTypesWithNoExportConfig() throws Exception {
File output = new File(directory, "all.graphml");
try {
TestUtil.testCall(db, "CALL apoc.export.graphml.all({file},null)", map("file", output.getAbsolutePath()), (r) -> assertResults(output, r, "database"));
} catch (QueryExecutionException e) {
Throwable except = ExceptionUtils.getRootCause(e);
TestCase.assertTrue(except instanceof RuntimeException);
assertEquals("Export to files not enabled, please set apoc.export.file.enabled=true in your neo4j.conf", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJsonByUrlInConfigFileWrongKey() throws Exception {
try {
testResult(db, "CALL apoc.load.json({key})",map("key","foo"), (r) -> {});
} catch (QueryExecutionException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof RuntimeException);
assertEquals("Can't read url or key invalid URL (foo) as json: no protocol: foo", except.getMessage());
throw e;
}
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJdbcUrlWithSpecialCharWithEmptyUserWithAuthentication() throws Exception {
try {
db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'',password:'Ap0c!#Db'}})", Util.map("url","jdbc:derby:derbyDB")).next();
} catch (IllegalArgumentException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof IllegalArgumentException);
assertEquals("In config param credentials must be passed both user and password.", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadXmlPreventXXEVulnerabilityThrowsQueryExecutionException() {
try {
testResult(db, "CALL apoc.load.xml('file:src/test/resources/xml/xxe.xml', '/catalog/book[genre=\"Computer\"]') yield value as result", (r) -> {});
} catch (QueryExecutionException e) {
// We want test that the cause of the exception is SAXParseException with the correct cause message
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof SAXParseException);
assertEquals("DOCTYPE is disallowed when the feature \"http://apache.org/xml/features/disallow-doctype-decl\" set to true.", except.getMessage());
throw e;
}
}

代码示例来源:origin: apache/tinkerpop

@Test
@LoadGraphWith(MODERN)
@IgnoreEngine(TraversalEngine.Type.STANDARD)
public void g_V_hasLabelXpersonX_pageRank_byXrankX_byXbothEX_rank_profile() {
final Traversal traversal = get_g_V_hasLabelXpersonX_pageRank_byXrankX_byXbothEX_rank_profile();
//printTraversalForm(traversal);
try {
traversal.iterate();
fail("Should have tossed an exception because multi-OLAP is unsolvable");
} catch (Exception ex) {
assertTrue(ex instanceof VerificationException || ExceptionUtils.getRootCause(ex) instanceof VerificationException);
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJdbcUrlWithSpecialCharWithoutUserWithAuthentication() throws Exception {
try {
db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{password:'Ap0c!#Db'}})", Util.map("url","jdbc:derby:derbyDB")).next();
} catch (IllegalArgumentException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof IllegalArgumentException);
assertEquals("In config param credentials must be passed both user and password.", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJdbcUrlWithSpecialCharWithEmptyPasswordWithAuthentication() throws Exception {
try {
db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'apoc',password:''}})", Util.map("url","jdbc:derby:derbyDB")).next();
} catch (IllegalArgumentException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof IllegalArgumentException);
assertEquals("In config param credentials must be passed both user and password.", except.getMessage());
throw e;
}
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test(expected = QueryExecutionException.class)
public void testLoadJdbcUrlWithSpecialCharWithoutPasswordWithAuthentication() throws Exception {
try {
db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'apoc'}})", Util.map("url","jdbc:derby:derbyDB")).next();
} catch (IllegalArgumentException e) {
Throwable except = ExceptionUtils.getRootCause(e);
assertTrue(except instanceof IllegalArgumentException);
assertEquals("In config param credentials must be passed both user and password.", except.getMessage());
throw e;
}
}

推荐阅读
  • 本文讨论了如何使用IF函数从基于有限输入列表的有限输出列表中获取输出,并提出了是否有更快/更有效的执行代码的方法。作者希望了解是否有办法缩短代码,并从自我开发的角度来看是否有更好的方法。提供的代码可以按原样工作,但作者想知道是否有更好的方法来执行这样的任务。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
  • 大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记
    本文介绍了大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记,包括outputFormat接口实现类、自定义outputFormat步骤和案例。案例中将包含nty的日志输出到nty.log文件,其他日志输出到other.log文件。同时提供了一些相关网址供参考。 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • r2dbc配置多数据源
    R2dbc配置多数据源问题根据官网配置r2dbc连接mysql多数据源所遇到的问题pom配置可以参考官网,不过我这样配置会报错我并没有这样配置将以下内容添加到pom.xml文件d ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
author-avatar
咿呀最有味先
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有