Try and recover from a BadLocationException thrown when inserting a string into the log area. This method must only be called on the AWT event handling thread.
(BadLocationException e,
String textToInsert, Style style)
| 467 | * handling thread. |
| 468 | */ |
| 469 | private void handleBadLocationException(BadLocationException e, |
| 470 | String textToInsert, Style style) { |
| 471 | originalErr.println("BadLocationException encountered when writing to " |
| 472 | + "the log area: " + e); |
| 473 | originalErr.println("trying to recover..."); |
| 474 | |
| 475 | Document newDocument = new DefaultStyledDocument(); |
| 476 | try { |
| 477 | StringBuilder sb = new StringBuilder(); |
| 478 | sb.append("An error occurred when trying to write a message to the log area. The log\n"); |
| 479 | sb.append("has been cleared to try and recover from this problem.\n\n"); |
| 480 | sb.append(textToInsert); |
| 481 | |
| 482 | newDocument.insertString(0, sb.toString(), style); |
| 483 | } catch(BadLocationException e2) { |
| 484 | // oh dear, all bets are off now... |
| 485 | e2.printStackTrace(originalErr); |
| 486 | return; |
| 487 | } |
| 488 | // replace the log area's document with the new one |
| 489 | setDocument(newDocument); |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * A print writer that uses UTF-8 to convert from char[] to byte[] |
no test coverage detected