Displays a stack trace. Use the setExceptionHandler method() to override with a custom exception handler.
(Throwable e)
| 2602 | /** Displays a stack trace. Use the setExceptionHandler |
| 2603 | method() to override with a custom exception handler. */ |
| 2604 | @AstroImageJ(reason = "Log exceptions to console as well", modified = true) |
| 2605 | public static void handleException(Throwable e) { |
| 2606 | e.printStackTrace(); |
| 2607 | if (exceptionHandler!=null) { |
| 2608 | exceptionHandler.handle(e); |
| 2609 | return; |
| 2610 | } |
| 2611 | if (Macro.MACRO_CANCELED.equals(e.getMessage())) |
| 2612 | return; |
| 2613 | CharArrayWriter caw = new CharArrayWriter(); |
| 2614 | PrintWriter pw = new PrintWriter(caw); |
| 2615 | e.printStackTrace(pw); |
| 2616 | String s = caw.toString(); |
| 2617 | String lineNumber = ""; |
| 2618 | if (s!=null && s.contains("ThreadDeath")) |
| 2619 | return; |
| 2620 | Interpreter interpreter = Thread.currentThread().getName().endsWith("Macro$") ? Interpreter.getInstance() : null; |
| 2621 | if (interpreter!=null) |
| 2622 | lineNumber = "\nMacro line number: " + interpreter.getLineNumber(); |
| 2623 | if (getInstance()!=null) { |
| 2624 | s = IJ.getInstance().getInfo()+lineNumber+"\n \n"+s; |
| 2625 | new TextWindow("Exception", s, 500, 340); |
| 2626 | } else |
| 2627 | log(s); |
| 2628 | } |
| 2629 | |
| 2630 | /** Installs a custom exception handler that |
| 2631 | overrides the handleException() method. */ |
no test coverage detected