View Single Post
Old 10-16-2012, 08:02 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That would be like:
PHP Code:
try
{
    ...
}
catch (
Exception ex)
{
    if (
ex instanceof NumberFormatException)
    {
        
JOptionPane.showMessageDialog(null"Failed to parse string as number");
    }
    if (
ex instanceof NumberFormatException)
    {
        
JOptionPane.showMessageDialog(null"Failed to retrieve tokens - input format invalid");
    }

Catch can be used to catch individual types. I prefer that myself:
PHP Code:
catch (NumberFormatException ex)
{
    
System.err.println("Invalid parse: " ex.getMessage());
}
catch (
ArrayIndexOutOfBoundsException ex)
{
    
System.err.println("Invalid access to array");
}
catch (
Exception ex)
{
    
System.err.println("Something went wrong: " ex.getMessage());

I'd recommend a final sweep with Exception if it can ever throw an unchecked exception somewhere as well. This way if you miss one it'll still get caught and not terminate the application.

JOptionPane.showConfirmDialog will return a result depending on what is clicked. Give it yes/no only options, and compare the results in the while clause: while (iConfirmContinue == JOptionPane.YES_OPTION);. Simply assign the confirm dialog to the iConfirmContinue.
Fou-Lu is offline   Reply With Quote