Testing a new warning window that includes the stack trace.
(String title, String message,
Throwable t, boolean fatal)
| 156 | * Testing a new warning window that includes the stack trace. |
| 157 | */ |
| 158 | static public void showTrace(String title, String message, |
| 159 | Throwable t, boolean fatal) { |
| 160 | if (title == null) title = fatal ? "Error" : "Warning"; |
| 161 | |
| 162 | if (Base.isCommandLine()) { |
| 163 | System.err.println(title + ": " + message); |
| 164 | if (t != null) { |
| 165 | t.printStackTrace(); |
| 166 | } |
| 167 | |
| 168 | } else { |
| 169 | StringWriter sw = new StringWriter(); |
| 170 | t.printStackTrace(new PrintWriter(sw)); |
| 171 | // Necessary to replace \n with <br/> (even if pre) otherwise Java |
| 172 | // treats it as a closed tag and reverts to plain formatting. |
| 173 | message = ("<html>" + message + |
| 174 | "<br/><font size=2><br/>" + |
| 175 | sw + "</html>").replaceAll("\n", "<br/>"); |
| 176 | |
| 177 | JOptionPane.showMessageDialog(new Frame(), message, title, |
| 178 | fatal ? |
| 179 | JOptionPane.ERROR_MESSAGE : |
| 180 | JOptionPane.WARNING_MESSAGE); |
| 181 | |
| 182 | if (fatal) { |
| 183 | System.exit(1); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | // ................................................................... |
no test coverage detected