【问题标题】:java Catch Exception root cause typejava Catch Exception 根本原因类型
【发布时间】:2014-05-09 14:35:37
【问题描述】:

我可以通过以下方式捕获抛出的异常:

Throwable temp = ExceptionUtils.getRootCause(e);

当我调试它时,我看到了 throwable 的类型,我怎样才能将这些信息作为字符串获取?我可以捕捉到发生异常的确切消息,但是它的类型呢?

【问题讨论】:

  • 什么是ExceptionUtils?
  • temp.getClass().getName()?
  • org.apache.commons.lang.exception.ExceptionUtils;
  • temp.getClass().getSimpleName() 然后。你需要学习阅读 javadoc。
  • 使用 temp.getClass().getSimpleName()

标签: java exception try-catch


【解决方案1】:

使用 cmets 中给出的代码用户 csn 来回答这个问题。下一个代码为您提供了引发异常的确切名称:

ExceptionUtils.getRootCause(e).getClass().getSimpleName() 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 2019-01-04
    • 1970-01-01
    相关资源
    最近更新 更多