Auslösen einer Exception
public static void checkAge(int age) throws Exception {
if(age < 18) {
throw new Exception();
}
}
Behandeln einer Exception
public static void main(String[] args) {
try {
Example.checkAge(2);
}
catch (Exception e) {
System.out.println("Age to low");
}
finally {
System.out.println("Always");
}
}