Java Stop Script Continuation Without System.exit(1);
I have a program and I am catching an error. I need the program to stop and stay idle if there is an exception.
I have this:
// Try to parse the integer just to make sure it's an integer.
try {
Integer.parseInt(celsiusTxtField.getText());
}
// Catch it if it's not an integer and murder the user for being stupid. They should know temperature consists of numbers and not letters.
catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "You did not submit a number. Please try again.", "General Error - Error #2", JOptionPane.ERROR_MESSAGE);
}
But, even though it shows the error message, it still continues on with the script.
This is probably really simple, but I'm new to Java, so please excuse my not 开发者_Python百科knowing.
I just found a way to do this.
Move everything under TRY, and that way, the CATCH is the last thing, so there's nothing else to be executed.
精彩评论