An exception is how Java reports a failure you can recover from, such as a missing file or a bad number. try wraps the risky lines. catch runs when a matching exception is thrown. finally runs whether the try succeeded or not.
Catch the specific type you can handle. An empty catch that ignores Exception hides bugs. If the method cannot fix the problem, declare throws and let the caller decide.
Example
The string is a valid integer, so the try block prints 12 and the catch is skipped.
public class Parse {
public static void main(String[] args) {
try {
int n = Integer.parseInt("12");
System.out.println(n);
} catch (NumberFormatException ex) {
System.out.println("Not a number");
}
}
}