Showing a JDialog whenever there is an exception I have made a method which I use to show the exception error through a JDialog window whenever there is one in my program.

For now I can pass it either a String or a subclass of Exception. At first I had two different methods for each one but now I combined them into one.

The showError method:

public static void showError(Object error) {
        String mainMessage = null;
        String title = null;
        if (error instanceof String) {
            mainMessage = (String) error;
            title = "Error!";
        } else if (error instanceof Exception) {
            Exception exceptionError = (Exception) error;
            mainMessage = "Message: " + exceptionError.getMessage()
                    + "\nStackTrace: " + Arrays.toString(exceptionError.getStackTrace());
            title = exceptionError.getClass().getName();
        }

        JOptionPane.showMessageDialog(null, mainMessage, title, JOptionPane.ERROR_MESSAGE);
    }
At first I had two different methods for each one but now I combined
  them into one.  


I would have made 3 methods instead of one.  

public static void showError(String errorMessage) {
    showError(errorMessage, "Error!");
}




public static void showError(Exception exceptionError) {
    String errorMessage = "Message: " + exceptionError.getMessage()
                + "\nStackTrace: " + Arrays.toString(exceptionError.getStackTrace());
    String title = exceptionError.getClass().getName();
    showError(errorMessage, title);
}




public static void showError(String errorMessage, String title) {
    JOptionPane.showMessageDialog(null, errorMessage, title, JOptionPane.ERROR_MESSAGE);
}  


In this way the readability is improved, unnecessary checks are removed as well as casts. 
And it is easier to maintain.