I wonder how is it possible to catch two exceptions which I have already caught separately?
private static boolean checkParameters(Scanner scnr) {
boolean result = true;
return result;
}
private static MnthInYear createMonthInYear() throws IllegalArgumentException {
String a = JOptionPane.showInputDialog(null, "Enter month and year");
Scanner sc = new Scanner(a);
MnthInYear obj = null;
if (checkParameters(sc)) {
try {
obj = new MnthInYear(sc.next(), sc.nextInt());
} catch (IllegalArgumentException exc) {
JOptionPane.showMessageDialog(null,"Wrong month!");
} catch (InputMismatchException exc2) {
JOptionPane.showMessageDialog(null,"Wrong year!");
} catch (NoSuchElementException exc3) {
JOptionPane.showMessageDialog(null,"No data!");
}
sc.close();
}
return obj;
}
And I need to make something like this:
} catch (IllegalArgumentException AND InputMismatchException) {
JOptionPane.showMessageDialog(null,"Wrong month and year!");
}
How can I get this?