Výnimku nemusíš odchytávať hneď, ako nastane, ale až na tom mieste, na ktorom ju chceš ošetriť - v tvojom prípade budeš mať ten while blok umiestnený vnútri try bloku.
Takže namiesto pôvodného:
while (...) {
try {
Integer.parseInt(...);
} catch (NumberFormatException e) {
...
}
}
Budeš mať niečo takéto:try {
while (...) {
Integer.parseInt(...);
}
} catch (NumberFormatException e) {
...
}