gpt4 book ai didi

Java异常: get detailMessage only

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:30 24 4
gpt4 key购买 nike

我试图从异常中仅获取detailMessage:

} catch (Exception e) {
logger.error(failed + e.getCause().getMessage()); }

日志文件包含

"Unable to find element with name == filter:P_ClearButtonDFI (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 30.24 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16' System info: host: 'OACVWMAX10006', ip: '10.29.19.64', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79' *** Element info: {Using=name, value=filter:P_ClearButtonDFI} Session ID: 5149a0b8-475e-4d89-a9d6-e5115e773da8 Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, ie.usePerProcessProxy=false, ignoreProtectedModeSettings=false, cssSelectorsEnabled=true, requireWindowFocus=false, initialBrowserUrl=http://localhost:21733/, handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]"

但我只想

Unable to find element with name == filter:P_ClearButtonDFI

最佳答案

我认为没有任何优雅的方式来访问它。

当然,您可以使用 Java 反射来访问私有(private)字段 Throwable.detailMessage 但这远非优雅:)

我在 Spring 中工作,异常经常继承 org.springframework.core.NestedRuntimeException ,它创建如下消息

detailedMessage + "; nested exception is " + cause.detailedMessage 
... + "; nested exception is " + cause.detailedMessage

我创建了一个简单的方法

private String extractDetailedMessage(Throwable e) {
final String message = e.getMessage();
if (message == null) {
return "";
}
final int tailIndex = StringUtils.indexOf(message, "; nested exception is");
if (tailIndex == -1) {
return message;
}
return StringUtils.left(message, tailIndex);
}

您可以根据您的情况轻松修改它:)恐怕您没有更好的了...

关于Java异常: get detailMessage only,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com