-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.6
-
x86
-
windows_95
Name: el35337 Date: 06/04/98
The documentation for SwingUtilities.invokeAndWait claims that it will throw an InvocationTargetException if the Runnable object throws an uncaught exception during its execution. This doesn't appear to be happening.
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class InvokeAndWaitTest
{
public static void main( String[] args )
{
JFrame frame = new JFrame( "Invoke And Wait Test" );
JButton run = new JButton( "Run" );
run.addActionListener( new ButtonHandler() );
frame.getContentPane().add( run, BorderLayout.SOUTH );
frame.setSize( 300, 200 );
frame.setVisible( true );
}
}
// This class will always throw an exception when run.
class ExceptionRunner implements Runnable
{
public void run()
{
System.out.println( "running..." );
throw new RuntimeException();
}
}
class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent evt )
{
// start a new thread, and run the ExceptionRunner on the AWT Thread
Runnable swingRunner =
new Runnable()
{
public void run()
{
try
{
SwingUtilities.invokeAndWait( new ExceptionRunner() );
// shouldn't make it here
System.out.println( "shouldn't reach this point" );
}
catch( java.lang.reflect.InvocationTargetException e )
{
System.err.println( "caught exception " + e );
}
catch( InterruptedException e2 )
{
System.err.println( "caught exception " + e2 );
}
}
};
new Thread( swingRunner ).start();
}
}
(Review ID: 32821)
======================================================================
- duplicates
-
JDK-4230713 invokeAndWait does not catch exceptions as documented
-
- Resolved
-