import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;

public class MultiCatch {
    public static void main(String[] args) throws IOException {
        BufferedReader pembaca = new BufferedReader(new StringReader("12\nabc"));

        for (int i = 1; i <= 2; i++) {
            try {
                String baris = pembaca.readLine();
                int nilai = Integer.parseInt(baris);
                System.out.println("baris " + i + ": " + nilai);
            } catch (IOException | NumberFormatException e) {
                System.out.println("baris " + i + " gagal: " + e.getClass().getSimpleName());
            }
        }

        pembaca.close();
    }
}
