-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTestOddNumException.java
More file actions
29 lines (26 loc) · 891 Bytes
/
TestOddNumException.java
File metadata and controls
29 lines (26 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.InputMismatchException;
import java.util.Scanner;
public class TestOddNumException {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
try{
while(true){
System.out.print("Enter number: ");
int number = input.nextInt();
ExceptionHandler(number);
}
} catch (OddNumberException ex) {
System.out.println(ex);
} catch (InputMismatchException ex) { //Error if not a number
System.out.println(ex);
} finally{
System.out.println("---FINALLY----");
}
System.out.println("END PROG");
}
public static void ExceptionHandler(int number) throws OddNumberException{
if(number%2!=0){
throw new OddNumberException("This is odd Number");
}
}
}