C:\Java 1\New folder (2)\Chapter 04\MyType.java:53: 'catch' without 'try' catch(NumberFormatException e) C:\Java 1\New folder (2)\Chapter 04\MyType.java:23: 'try' without 'catch' or 'finally' try
import java.io.*; import javax.swing.JOptionPane; public class MyType { public static void main(String[] args) { String strChoice = "", strTryString, strTryInt, strTryDouble; int choice, tryInt; double tryDouble; boolean done = false; while(!done) { try // 1st error { System.out.println("What's my type?"); strChoice = JOptionPane.showInputDialog(null,"\n\n\n1) String\n2) integer\n3) double\n4) Quit the program"); choice = Integer.parseInt(strChoice); switch(choice) { case 1: JOptionPane.showMessageDialog(null, "Correct, any input can be saved as a String"); break; case 2: JOptionPane.showMessageDialog(null, "Correct!"); tryInt = Integer.parseInt(strChoice); break; case 3: JOptionPane.showMessageDialog(null, "Correct!"); tryDouble = Integer.parseInt(strChoice); break; case 4: done = true; JOptionPane.showMessageDialog(null, "Exit."); System.exit(0); break; default: throw new NumberFormatException(); } catch(NumberFormatException e) // 2nd error { JOptionPane.showMessageDialog(null, "Invalid, try again."); } } } } }
try { ... } catch (...) { ... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)