Lektion 10 af 10
Exception handling
Exceptions er fejl under programkørsel. Brug try og catch til at håndtere dem, og finally til kode, der altid skal køre.
JAVA
public class Main {
public static void main(String[] args) {
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero!");
} finally {
System.out.println("Cleanup done.");
}
}
}