开发者

Using newline in JFace 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(), t开发者_运维问答hrowable));
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?


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.


I seem to remember this working with just '\n' but I was also using:

ExceptionUtils.getStackTrace( ex );

From Apache Commons-Lang.


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


Wrap the Exception with a new that contains the stacktrace as message.

The code is here https://stackoverflow.com/a/19703255/2064294

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜