Exception handling is the way to handle the unexpected circumstances like runtime errors. So when the unexpected circumstance occurs, the program control is transferred to special functions known as handlers.
Syntax:
try{
// the protected code.
}
Catch(Exception_Name){
// the code to run when unexpected circumstance occurs.
}
For example:-
packge com.company;
import java.util.Scanner;
public class Learner{
public static void main(String[]args){
try{
int divide by zero=6/0;
System.out.println("Rest of code in try block");
}
catch(Arthmatic exception e){
System.out.println("Arithmatic exception =>" +e.get message());
}
}
}