热门标签 | 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;
}
}

推荐阅读
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社区 版权所有