Arun KumarWhat is Exception Handling? Exception Handling in Java is a mechanism to handle runtime...
Exception Handling in Java is a mechanism to handle runtime errors so that the normal flow of the program can be maintained.
An exception is an unwanted or unexpected event that occurs during program execution and disrupts the normal flow of instructions.
try → block where code is writtencatch → handles the exceptionpublic class ExceptionExample {
public static void main(String[] args) {
try {
int a = 10;
int b = 0;
int result = a / b; // Exception occurs here
System.out.println(result);
}
catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
}
}