Подскажите где ошибка
Исключение вроде ловлю, если вводить буквы то вывожу исключение на экран
Направьте пжл.
package com.javarush.task.task14.task1420;
import java.util.*;
import java.io.*;
/*
НОД
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
String first = reader.readLine();
String second = reader.readLine();
int a = Integer.parseInt(first);
int b = Integer.parseInt(second);
ArrayList<Integer> arrayForA = new ArrayList<>();
ArrayList<Integer> arrayForB = new ArrayList<>();
ArrayList<Integer> arrayForTOTAL = new ArrayList<>();
for (int i = 1; i < a; i++) {
if (a % i == 0) {
arrayForA.add(i);
}
}
for (int i = 1; i < b; i++) {
if (b % i == 0) {
arrayForB.add(i);
}
}
int nod = 0;
if (a < b) {
for (int i = arrayForB.size() - 1; i > -1; i--) {
if (a % arrayForB.get(i) == 0)
nod = arrayForB.get(i);
arrayForTOTAL.add(nod);
}
}
if (a > b) {
for (int i = arrayForA.size() - 1; i > -1; i--) {
if (b % arrayForA.get(i) == 0)
nod = arrayForA.get(i);
arrayForTOTAL.add(nod);
}
}
Collections.sort(arrayForTOTAL);
System.out.println((arrayForTOTAL.get(arrayForTOTAL.size() - 1)));
reader.close();
}catch (Exception e){
e.printStackTrace();
}
}
}