Try-catch statements, in conjunction with exceptions, are mainly used to catch program errors.
try {
// try to execute this block of code
}
catch (Exception) {
// handle error block code
}
try {
// try to excecute this block of code
} catch (RuntimeException e) {
// Catch exceptions of class "RuntimeException"
System.out.println("runtime exception");
} catch (NumberFormatException e) {
// Catch exceptions of class "NumberFormatException"
System.out.println("number format exception");
} catch (Exception e) {
// Catch exceptions of class "Exception"
System.out.println("other exception");
} finally {
// Is executed if at least one statement from the try block has been executed
System.out.println("'try-catch' finished.");
}