public static void showErrorDialog(Throwable thrown) {
            StackTraceElement[] stackTraceElements = thrown.getStackTrace();
            int counter = 0;
            StringBuilder stackTraceBuffer = new StringBuilder();
            for (int i = 0; i < stackTraceElements.length; i++) {
                StackTraceElement stackTraceElement = stackTraceElements[i];
                stackTraceBuffer.append(stackTraceElement.toString()).append("\n");
                if (counter >= SHOW_LINES) {
                    break;
                }
                counter++;
            }
            if (stackTraceElements.length > SHOW_LINES) {
                stackTraceBuffer.append("and ").append(stackTraceElements.length - SHOW_LINES).append(" more ...");
            }

            final String errorStackTrace = stackTraceBuffer.toString();
            final String errorMessage = thrown.getMessage();
            Object[] options = {"Close", "Restart"};
            int result = JOptionPane.showOptionDialog(findActiveFrame(),
                                                      errorMessage + "\n\n" + errorStackTrace,
                                                      "Exception Occurred",
                                                      JOptionPane.YES_NO_OPTION,
                                                      JOptionPane.ERROR_MESSAGE,
                                                      null,
                                                      options,
                                                      options[0]);
            if (result == JOptionPane.NO_OPTION) {
                LOG.debug("Try to restore UI");
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Frame f = findActiveFrame();
                        if (f != null && f instanceof Viewer) {
                            Viewer viewer = (Viewer)f;
                            HTMGraphicInterface.Config cfg;
                            InputStream in = getClass().getResourceAsStream("/config.xml");
                            try {
                                cfg = Serializer.INSTANCE.loadHTMParameters(in);
                                viewer.reloadHTMInterface(cfg);
                            } catch (Exception e) {
                                LOG.error("Error loading HTM parameters from config.xml resource", e);
                            } finally {
                                try {
                                    if (in != null) in.close();
                                } catch (IOException ex) {
                                    LOG.error("Can't close config.xml resource stream");
                                }
                            }
                        }
                    }
                });
            }
        }