Java JOptionPane Message showExceptionMessage(Component parent, Throwable t)

Here you can find the source of showExceptionMessage(Component parent, Throwable t)

Description

Shows a message box with exception details.

License

Open Source License

Parameter

Parameter Description
parent Parent component of the message bos.
t Throwable with the exception details.

Declaration

public static void showExceptionMessage(Component parent, Throwable t) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Main {
    /**/*from   w w  w. ja v a2s  .com*/
     * Shows a message box with exception details.
     * 
     * @param parent Parent component of the message bos.
     * @param t Throwable with the exception details.
     */
    public static void showExceptionMessage(Component parent, Throwable t) {

        StringBuilder sb = new StringBuilder();

        sb.append("An unexpected error occured during the execution of the requested task.\n");
        sb.append("The error data can be seen below:\n\n");

        sb.append(t.getLocalizedMessage());
        sb.append(t.toString()).append("\n");
        sb.append("Stack Trace:\n");

        for (StackTraceElement e : t.getStackTrace()) {
            sb.append(e.toString()).append("\n");
        }

        JTextArea tArea = new JTextArea(20, 50);
        tArea.setText(sb.toString());
        JScrollPane sp = new JScrollPane(tArea);

        JOptionPane.showMessageDialog(parent, sp, "ERROR", JOptionPane.ERROR_MESSAGE);

    }
}

Related

  1. show(String title, int type, Object message, Object[] options, Object initialOption)
  2. showActionFailedWithExceptionMessage(final Component parent, final Exception ex)
  3. showAlert(String message)
  4. showException(Component c, String message, Throwable t)
  5. showException(String message, Exception ex)
  6. showExceptionMessage(Component parentComponent, Exception exception)
  7. showExceptionMessage(Exception e)
  8. showExceptionMessage(Exception e)
  9. showInput(Component parent, String message, String initValue)