在 JFace ErrorDialog 中使用换行符
有没有人设法使用换行符(\n、\r)在 JFace ErrorDialog 中显示详细错误消息?
我正在尝试将 StackTrace 显示为详细消息,但它仅显示在一行中
StringBuffer sbStackTrace = new StringBuffer();
for (StackTraceElement ste : throwable.getStackTrace()) {
sbStackTrace.append(ste.toString()).append('\n');
}
final IStatus status = new Status(IStatus.ERROR, pluginId, statusMsg, new Throwable(sbStackTrace.toString(), throwable));
ErrorDialog dialog = new ErrorDialog(shell, "Error", customMessage, status, IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR)
打开时,ErrorDialog 显示我想要的所有内容,但详细消息的格式不正确。
有什么想法吗?
Has anybody managed to show a detail error message in the JFace ErrorDialog using newline (\n, \r) character?
I'm trying to display the StackTrace as a detail message, but it is only shown in one line
StringBuffer sbStackTrace = new StringBuffer();
for (StackTraceElement ste : throwable.getStackTrace()) {
sbStackTrace.append(ste.toString()).append('\n');
}
final IStatus status = new Status(IStatus.ERROR, pluginId, statusMsg, new Throwable(sbStackTrace.toString(), throwable));
ErrorDialog dialog = new ErrorDialog(shell, "Error", customMessage, status, IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR)
On open the ErrorDialog shows eveything I want, except that the detail message is not properly formatted.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 ErrorDialog.java 的源,看起来对话框只包含一个
IStatus 每行,但如果该
IStatus
有子项,它将在后续行中包含它们。因此,您需要构建一个MultiStatus
对象或创建您自己的IStatus
实现。Looking at the
ErrorDialog.populateList(List, IStatus, int, boolean)
method in the source for ErrorDialog.java, it looks like the dialog only includes oneIStatus
per line, but if thatIStatus
has children, it will include them on subsequent lines. So you'll need to either build aMultiStatus
object or create your own implementation ofIStatus
.我似乎记得只使用“\n”,但我也使用:
ExceptionUtils.getStackTrace( ex );
来自 Apache Commons-Lang。
I seem to remember this working with just '\n' but I was also using:
ExceptionUtils.getStackTrace( ex );
From Apache Commons-Lang.
为了达到同样的目的,也可以构建 MultiStatus。 MultiStatus 可以将下一个 IStatus 作为子项,并且由于详细信息区域中的 ErrorDialog 每行显示一个 IStatus,因此您将得到相同的结果。
请在我的其他回复中查看该技巧https://stackoverflow.com/a/9404081/915931
To achieve the same it is also possible to build MultiStatus. MultiStatus can have next IStatus(es) as children and because ErrorDialog in detail area is showing one IStatus per line, you will get the same result.
Please see the trick in action in my other reply https://stackoverflow.com/a/9404081/915931
使用包含堆栈跟踪作为消息的新异常来包装异常。
代码在这里 https://stackoverflow.com/a/19703255/2064294
Wrap the Exception with a new that contains the stacktrace as message.
The code is here https://stackoverflow.com/a/19703255/2064294