Hello! I am new in java and I have this code that will throw an exception if the numerator input is not an integer and will stop the loop process when the user input 'e' as its numerator. Thank you for your help in advance.
package org.alibata.training.codes.exceptions;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TrapDivide {
public static void main(String[] args){
TrapDivide trapDiv = new TrapDivide();
Scanner scan = new Scanner(System.in);
int quo;
int num = 1;
int den;
int c = (char)'e';
while(num != c){
System.out.println("Enter the numerator: ");
num = scan.nextInt();
System.out.println("Enter the denominator: ");
den = scan.nextInt();
try {
quo = trapDiv.divIntegers(num, den);
System.out.println(num + " /" + den + " is " + quo);
} catch (NotValidNumeratorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotValidDenominatorException e) {
System.out.println( );
e.printStackTrace();
} catch (InputMismatchException ex) {
System.out.println("wrong");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public int divIntegers(int num, int den)throws NotValidNumeratorException, NotValidDenominatorException, Exception{
if(num == 0){
throw new NotValidNumeratorException();
} else if(den == 0){
throw new NotValidDenominatorException();
}
return num / den;
}
}