我有以下代码示例捕获异常并使用IllegalStateException包装它们。
try {
do my things...
} catch (final Exception e) {
throw new IllegalStateException("Exception happened", e)
}
这一切正常,但在运行集成测试时,当记录IllegalStateException时,它没有显示由此引起的。
java.lang.IllegalStateException: Exception happened
at org.apache.zookeeper.KeeperException.create(KeeperException.java:111)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:1155)
at org.apache.curator.framework.imps.GetDataBuilderImpl$4.call(GetDataBuilderImpl.java:304)
at org.apache.curator.framework.imps.GetDataBuilderImpl$4.call(GetDataBuilderImpl.java:293)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:108)
at org.apache.curator.framework.imps.GetDataBuilderImpl.pathInForeground(GetDataBuilderImpl.java:290)
at org.apache.curator.framework.imps.GetDataBuilderImpl.forPath(GetDataBuilderImpl.java:281)
at org.apache.curator.framework.imps.GetDataBuilderImpl.forPath(GetDataBuilderImpl.java:42)
at <my package line of "throw new IllegalStateException">.getConfig(ZookeeperConfigProvider.java:55)
at <my package>.getConfig(ZookeeperConfigProvider.java:49)
at <my package>.test_get_config_missing_resource(ZookeeperConfigProviderIT.java:118)
我们正在使用logback,java 8和JUnit
Logback配置(但这看起来并不是由logback输出)
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
为什么会发生这种情况?
答案 0 :(得分:1)
原因是代码。
检查此处的grep代码以获取KeeperException create method Grep Code KeeperException
它只是抛出异常但不添加任何消息。这就是为什么你没有看到任何有用的东西。
此外,因为它只是在没有记录原始问题的情况下返回。