Java JOptionPane Message showException(Component c, String message, Throwable t)

Here you can find the source of showException(Component c, String message, Throwable t)

Description

Utility method to display a popup with the provided message ant Throwable

License

Open Source License

Parameter

Parameter Description
c The parent component of the message popup
message The message to display on the popup
t The exception to display on the popup

Declaration

public static void showException(Component c, String message, Throwable t) 

Method Source Code


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

import java.io.*;
import java.awt.*;
import javax.swing.*;

public class Main {
    /**//from  w ww  . ja  v a  2s  .c o  m
     * Utility method to display a popup with the provided Throwable
     * @param c The parent component of the message popup
     * @param t The exception to display on the popup
     */
    public static void showException(Component c, Throwable t) {
        showException(c, t.getMessage(), t);
    }

    /**
     * Utility method to display a popup with the provided message ant Throwable
     * @param c The parent component of the message popup
     * @param message The message to display on the popup
     * @param t The exception to display on the popup
     */
    public static void showException(Component c, String message, Throwable t) {
        if (t == null) {
            t = new Exception("Unknown Exception");
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        if (message == null) {
            message = t.getClass().getName();
        }
        String stackTrace = baos.toString();
        message += System.getProperty("line.separator") + stackTrace;

        JOptionPane.showMessageDialog(c, message, "Error Message", JOptionPane.ERROR_MESSAGE);
    }
}

Related

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