Index: trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java	(revision 10066)
+++ trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java	(revision 10067)
@@ -5,4 +5,5 @@
 
 import java.awt.Component;
+import java.awt.GraphicsEnvironment;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -44,5 +45,5 @@
     private static boolean suppressExceptionDialogs;
 
-    private static class BugReporterThread extends Thread {
+    static final class BugReporterThread extends Thread {
 
         private final class BugReporterWorker implements Runnable {
@@ -57,64 +58,5 @@
                 // Then ask for submitting a bug report, for exceptions thrown from a plugin too, unless updated to a new version
                 if (pluginDownloadTask == null) {
-                    String[] buttonTexts = new String[] {tr("Do nothing"), tr("Report Bug")};
-                    String[] buttonIcons = new String[] {"cancel", "bug"};
-                    int defaultButtonIdx = 1;
-                    String message = tr("An unexpected exception occurred.<br>" +
-                            "This is always a coding error. If you are running the latest<br>" +
-                            "version of JOSM, please consider being kind and file a bug report."
-                            );
-                    // Check user is running current tested version, the error may already be fixed
-                    int josmVersion = Version.getInstance().getVersion();
-                    if (josmVersion != Version.JOSM_UNKNOWN_VERSION) {
-                        try {
-                            int latestVersion = Integer.parseInt(new WikiReader().
-                                    read(Main.getJOSMWebsite()+"/wiki/TestedVersion?format=txt").trim());
-                            if (latestVersion > josmVersion) {
-                                buttonTexts = new String[] {tr("Do nothing"), tr("Update JOSM"), tr("Report Bug")};
-                                buttonIcons = new String[] {"cancel", "download", "bug"};
-                                defaultButtonIdx = 2;
-                                message = tr("An unexpected exception occurred. This is always a coding error.<br><br>" +
-                                        "However, you are running an old version of JOSM ({0}),<br>" +
-                                        "instead of using the current tested version (<b>{1}</b>).<br><br>"+
-                                        "<b>Please update JOSM</b> before considering to file a bug report.",
-                                        String.valueOf(josmVersion), String.valueOf(latestVersion));
-                            }
-                        } catch (IOException | NumberFormatException e) {
-                            Main.warn("Unable to detect latest version of JOSM: "+e.getMessage());
-                        }
-                    }
-                    // Show dialog
-                    ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), buttonTexts);
-                    ed.setButtonIcons(buttonIcons);
-                    ed.setIcon(JOptionPane.ERROR_MESSAGE);
-                    ed.setCancelButton(1);
-                    ed.setDefaultButton(defaultButtonIdx);
-                    JPanel pnl = new JPanel(new GridBagLayout());
-                    pnl.add(new JLabel("<html>" + message + "</html>"), GBC.eol());
-                    JCheckBox cbSuppress = null;
-                    if (exceptionCounter > 1) {
-                        cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session."));
-                        pnl.add(cbSuppress, GBC.eol());
-                    }
-                    ed.setContent(pnl);
-                    ed.setFocusOnDefaultButton(true);
-                    ed.showDialog();
-                    if (cbSuppress != null && cbSuppress.isSelected()) {
-                        suppressExceptionDialogs = true;
-                    }
-                    if (ed.getValue() <= 1) {
-                        // "Do nothing"
-                        return;
-                    } else if (ed.getValue() < buttonTexts.length) {
-                        // "Update JOSM"
-                        try {
-                            Main.platform.openUrl(Main.getJOSMWebsite());
-                        } catch (IOException e) {
-                            Main.warn("Unable to access JOSM website: "+e.getMessage());
-                        }
-                    } else {
-                        // "Report bug"
-                        askForBugReport(e);
-                    }
+                    askForBugReport(e);
                 } else {
                     // Ask for restart to install new plugin
@@ -131,7 +73,79 @@
          * @param t the exception
          */
-        BugReporterThread(Throwable t) {
+        private BugReporterThread(Throwable t) {
             super("Bug Reporter");
             this.e = t;
+        }
+
+        static void askForBugReport(final Throwable e) {
+            String[] buttonTexts = new String[] {tr("Do nothing"), tr("Report Bug")};
+            String[] buttonIcons = new String[] {"cancel", "bug"};
+            int defaultButtonIdx = 1;
+            String message = tr("An unexpected exception occurred.<br>" +
+                    "This is always a coding error. If you are running the latest<br>" +
+                    "version of JOSM, please consider being kind and file a bug report."
+                    );
+            // Check user is running current tested version, the error may already be fixed
+            int josmVersion = Version.getInstance().getVersion();
+            if (josmVersion != Version.JOSM_UNKNOWN_VERSION) {
+                try {
+                    int latestVersion = Integer.parseInt(new WikiReader().
+                            read(Main.getJOSMWebsite()+"/wiki/TestedVersion?format=txt").trim());
+                    if (latestVersion > josmVersion) {
+                        buttonTexts = new String[] {tr("Do nothing"), tr("Update JOSM"), tr("Report Bug")};
+                        buttonIcons = new String[] {"cancel", "download", "bug"};
+                        defaultButtonIdx = 2;
+                        message = tr("An unexpected exception occurred. This is always a coding error.<br><br>" +
+                                "However, you are running an old version of JOSM ({0}),<br>" +
+                                "instead of using the current tested version (<b>{1}</b>).<br><br>"+
+                                "<b>Please update JOSM</b> before considering to file a bug report.",
+                                String.valueOf(josmVersion), String.valueOf(latestVersion));
+                    }
+                } catch (IOException | NumberFormatException ex) {
+                    Main.warn("Unable to detect latest version of JOSM: "+ex.getMessage());
+                }
+            }
+            // Build panel
+            JPanel pnl = new JPanel(new GridBagLayout());
+            pnl.add(new JLabel("<html>" + message + "</html>"), GBC.eol());
+            JCheckBox cbSuppress = null;
+            if (exceptionCounter > 1) {
+                cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session."));
+                pnl.add(cbSuppress, GBC.eol());
+            }
+            if (GraphicsEnvironment.isHeadless()) {
+                return;
+            }
+            // Show dialog
+            ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), buttonTexts);
+            ed.setButtonIcons(buttonIcons);
+            ed.setIcon(JOptionPane.ERROR_MESSAGE);
+            ed.setCancelButton(1);
+            ed.setDefaultButton(defaultButtonIdx);
+            ed.setContent(pnl);
+            ed.setFocusOnDefaultButton(true);
+            ed.showDialog();
+            if (cbSuppress != null && cbSuppress.isSelected()) {
+                suppressExceptionDialogs = true;
+            }
+            if (ed.getValue() <= 1) {
+                // "Do nothing"
+                return;
+            } else if (ed.getValue() < buttonTexts.length) {
+                // "Update JOSM"
+                try {
+                    Main.platform.openUrl(Main.getJOSMWebsite());
+                } catch (IOException ex) {
+                    Main.warn("Unable to access JOSM website: "+ex.getMessage());
+                }
+            } else {
+                // "Report bug"
+                try {
+                    JPanel p = buildPanel(e);
+                    JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE);
+                } catch (Exception ex) {
+                    Main.error(ex);
+                }
+            }
         }
 
@@ -182,13 +196,4 @@
     }
 
-    private static void askForBugReport(final Throwable e) {
-        try {
-            JPanel p = buildPanel(e);
-            JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE);
-        } catch (Exception e1) {
-            Main.error(e1);
-        }
-    }
-
     static JPanel buildPanel(final Throwable e) {
         StringWriter stack = new StringWriter();
Index: trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java	(revision 10066)
+++ trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java	(revision 10067)
@@ -49,4 +49,5 @@
 
     private final String statusText;
+    private String errorMessage;
 
     /**
@@ -54,5 +55,5 @@
      * @param statusText The status text to send.
      */
-    public BugReportSender(String statusText) {
+    protected BugReportSender(String statusText) {
         super("Bug report sender");
         this.statusText = statusText;
@@ -101,5 +102,5 @@
                 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                 Document document = builder.parse(in);
-                return retriveDebugToken(document);
+                return retrieveDebugToken(document);
             }
         } catch (IOException | SAXException | ParserConfigurationException | XPathExpressionException t) {
@@ -108,9 +109,9 @@
     }
 
-    private String getJOSMTicketURL() {
+    private static String getJOSMTicketURL() {
         return Main.getJOSMWebsite() + "/josmticket";
     }
 
-    private String retriveDebugToken(Document document) throws XPathExpressionException, BugReportSenderException {
+    private static String retrieveDebugToken(Document document) throws XPathExpressionException, BugReportSenderException {
         XPathFactory factory = XPathFactory.newInstance();
         XPath xpath = factory.newXPath();
@@ -134,9 +135,9 @@
 
     private void failed(String string) {
+        errorMessage = string;
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
-                JPanel errorPanel = new JPanel();
-                errorPanel.setLayout(new GridBagLayout());
+                JPanel errorPanel = new JPanel(new GridBagLayout());
                 errorPanel.add(new JMultilineLabel(
                         tr("Opening the bug report failed. Please report manually using this website:")),
@@ -149,4 +150,12 @@
             }
         });
+    }
+
+    /**
+     * Returns the error message that could have occured during bug sending.
+     * @return the error message, or {@code null} if successful
+     */
+    public final String getErrorMessage() {
+        return errorMessage;
     }
 
@@ -164,7 +173,10 @@
      * Opens the bug report window on the JOSM server.
      * @param statusText The status text to send along to the server.
+     * @return bug report sender started thread
      */
-    public static void reportBug(String statusText) {
-        new BugReportSender(statusText).start();
+    public static BugReportSender reportBug(String statusText) {
+        BugReportSender sender = new BugReportSender(statusText);
+        sender.start();
+        return sender;
     }
 }
