在 JFace ErrorDialog 中使用换行符

发布于 2024-10-12 09:14:13 字数 609 浏览 5 评论 0原文

有没有人设法使用换行符(\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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫烠⑼条掵仅有一顆心 2024-10-19 09:14:13

查看 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 one IStatus per line, but if that IStatus has children, it will include them on subsequent lines. So you'll need to either build a MultiStatus object or create your own implementation of IStatus.

蹲墙角沉默 2024-10-19 09:14:13

我似乎记得只使用“\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.

妥活 2024-10-19 09:14:13

为了达到同样的目的,也可以构建 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

别理我 2024-10-19 09:14:13

使用包含堆栈跟踪作为消息的新异常来包装异常。

代码在这里 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文