Skip to content

Commit 1aeaf77

Browse files
YoungJulesEswcvlad
authored andcommitted
Try to get a little more information into the error dialogue
Update getTraceString in ErrorDialogPane to show the error message and cause, if available.
1 parent 43eced6 commit 1aeaf77

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/com/itextpdf/rups/model/ErrorDialogPane.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This file is part of the iText (R) project.
4949
import java.awt.Toolkit;
5050
import java.awt.Window;
5151
import java.awt.event.HierarchyEvent;
52+
import java.util.Optional;
5253
import javax.swing.JOptionPane;
5354
import javax.swing.JScrollPane;
5455
import javax.swing.JTextArea;
@@ -143,7 +144,17 @@ private static void limitDialogSize(Window window) {
143144
private static String getTraceString(Throwable th) {
144145
final StringWriter sw = new StringWriter();
145146
final PrintWriter pw = new PrintWriter(sw);
146-
th.printStackTrace(pw);
147+
final Optional<Throwable> chuckIt = Optional.ofNullable(th);
148+
chuckIt.map(Throwable::getLocalizedMessage)
149+
.ifPresent(pw::println);
150+
chuckIt.map(Throwable::getCause)
151+
.map(Throwable::getLocalizedMessage)
152+
.ifPresent((String msg) -> {
153+
pw.print("Caused by: ");
154+
pw.println(msg);
155+
});
156+
pw.append("[Stack Trace]\n");
157+
chuckIt.ifPresent(throwable -> throwable.printStackTrace(pw));
147158
return sw.toString();
148159
}
149160
}

0 commit comments

Comments
 (0)