[ JAVA ] Exceptions Exercise 1

preview_player
Показать описание
What is an Exception ?

An #exception is an unwanted or unexpected event, which occurs during the execution of a program i.e at run time, that disrupts the normal flow of the program’s instructions.
class Except extends Exception {
}

public class exception1 {
public static void f(int n) throws Except {
try {
if (n != 1)
throw new Except();
} catch (Except e) {
throw e;
} finally {
}
}

public static void main(String[] args) {
int n = 0;
try {
for (n = 1; n ◄ 5; n++) // ◄ = less than
f(n);
} catch (Except e) {
} finally {
}
}
}
#java
Рекомендации по теме