Class ExceptionDialog
This Swing-based dialog provides a user-friendly way to display exceptions and their stack traces in graphical applications. It shows:
- Exception type (class name)
- Error message
- Cause message (if available)
- Complete stack trace
Example usage:
try {
// some operation that might fail
} catch (Exception e) {
new ExceptionDialog(e);
}
The dialog opens a new JFrame window with the exception details. The window is 800x600 pixels and centered on screen.
Note: This class requires a graphical environment and Swing libraries. It is not suitable for headless or server-side applications. For non-graphical error reporting, use standard logging or console output instead.
-
Constructor Summary
ConstructorsConstructorDescriptionExceptionDialog(Exception exception) Creates and displays an exception dialog for the given exception. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidMain method for testing the exception dialog.voidshowException(Exception exception) Displays the exception in a new JFrame window.
-
Constructor Details
-
ExceptionDialog
Creates and displays an exception dialog for the given exception.The dialog is shown immediately upon construction. This is a convenience for quick exception display without additional setup.
- Parameters:
exception- the exception to display. Must not be null.
-
-
Method Details
-
main
Main method for testing the exception dialog.This method creates a sample exception with a cause and displays it in the dialog, allowing developers to test the dialog appearance without needing actual exceptions.
- Parameters:
args- command line arguments (ignored).
-
showException
Displays the exception in a new JFrame window.Creates a window with:
- Top panel showing exception type, message, and cause
- Center panel showing the stack trace in a text area
The window is sized 800x600 pixels and centered on the screen. It closes when the user clicks the close button (DISPOSE_ON_CLOSE).
- Parameters:
exception- the exception to display. Must not be null.
-