正在加载图片...
Catch Runtime errors mport javax. swing. JOptionPane; ublic class test public static void main(String[] args) try i stril t= JOptionPane. showInput Dialog(null Please enter an int number Integer parseInt(input)i If an exception occurs on this line, the rest lines in the try clause are skipped and the control is transferred to the catch clause // Display the result JOptionPane showMessageDialog(null The number entered is+ number JOptionPane showMessageDialog(null Incorrect input: an integer is required")i After the exception is caught and processed, the control is transferred to the next statement after the try-catch block System. out. println(" Execution continues System. exit(0) duction to JavaLiang,Introduction to Java Programming,revised by Dai-kaiyu 5 Catch Runtime Errors import javax.swing.JOptionPane; public class Test { public static void main(String[] args) { try { String input = JOptionPane.showInputDialog(null, "Please enter an integer"); int number = Integer.parseInt(input); // Display the result JOptionPane.showMessageDialog(null, "The number entered is " + number); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Incorrect input: an integer is required"); } System.out.println("Execution continues ..."); System.exit(0); } } If an exception occurs on this line, the rest lines in the try clause are skipped and the control is transferred to the catch clause. After the exception is caught and processed, the control is transferred to the next statement after the try-catch block
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有