Java JOptionPane Message excMsg(String msg, Exception ex)

Here you can find the source of excMsg(String msg, Exception ex)

Description

Exception message dialog.

License

Open Source License

Parameter

Parameter Description
msg a parameter
ex a parameter

Declaration

public static void excMsg(String msg, Exception ex) 

Method Source Code

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

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class Main {
    public static final String LS = System.getProperty("line.separator");

    /**//from  www .  ja  v a  2  s  . com
     * Exception message dialog. Displays message plus the exception and
     * exception message.
     * 
     * @param msg
     * @param ex
     */
    public static void excMsg(String msg, Exception ex) {
        final String fullMsg = msg += LS + "Exception: " + ex + LS + ex.getMessage();
        // Show it in a message box
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null, fullMsg, "Error", JOptionPane.ERROR_MESSAGE);
                System.out.println(fullMsg);
            }
        });
    }

    /**
     * Exception message dialog. Displays message plus the error and error
     * message.
     * 
     * @param msg
     * @param ex
     */
    public static void excMsg(String msg, Error ex) {
        final String fullMsg = msg += LS + "Error: " + ex + LS + ex.getMessage();
        // Show it in a message box
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null, fullMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }

    /**
     * Exception message dialog. Displays message plus the throwable and
     * throwable message.
     * 
     * @param msg
     * @param t
     */
    public static void excMsg(String msg, Throwable t) {
        final String fullMsg = msg += LS + "Throwable: " + t + LS + t.getMessage();
        // Show it in a message box
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null, fullMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }
}

Related

  1. displayInputMessage(String title, String message, String defaultInput)
  2. displayMessage(Component parent, String string, String title)
  3. displayMessage(Component parentComponent, String message, String windowTitle, int messageType)
  4. displayMessage(String message)
  5. displayMessagePane(String desc, String title)
  6. excMsg(String msg, Exception ex)
  7. excMsg(String msg, Throwable t)
  8. exibeMsg(String msg, int tipoMsg)
  9. getIconForType(int messageType)