Java throws Exception
objects to indicate a problem. These cannot be ignored.
try-catch-finally
public class HelloThere {
public static void main(String[] args) {
try {
System.out.println("Hello " + args[0]);
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Hello Whoever you are.");
}
finally {
System.out.println("How are you?");
}
}
}
Checked exceptions must be caught at compile time. Runtime exceptions do not
need to be. Errors often cannot be.