Java Reference
In-Depth Information
[filename="src/main/java/gui/ThreadBasedCatcher.java", language="java",
identifier="main"]
snippet~~~~
ERROR: Failed to load src/main/java/gui/ThreadBasedCatcher.java
snippet~~~~
Figure 14-7
shows the program running; pushing the button produced this output:
You crashed thread AWT-EventQueue-0
Exception was: java..lang.RuntimeException: You asked for it.
Figure 14-7. ThreadBasedCatcher running
To display the caught exceptions, you may want to show each one in a dialog. My API class
com.darwinsys.swingui.ErrorUtil
contains a method:
public static void showExceptions(Component parent, Throwable t)
The online version of ThreadBasedCatcher (
Action Handling Using Anonymous Inner
This method displays the
Throwable
(and, if applicable, any nested exceptions) in an error
dialog:
/**
* Show the given Exception (and any nested Exceptions) in JOptionPane(s).
*/
public
public static
static
void
void
showExceptions
(
Component parent
,
Throwable theExc
) {
Throwable next
=
null
null
;
ddo
{
String className
=
theExc
.
getClass
().
getName
();
String message
=
className
;
iif
(
theExc
instanceof
instanceof
SQLException
) {