Please see below code for Try Catch Statement
package practice;
public class IfElse {
public static void main(String[] args) {
try {
int number = 30 ;
System.out.println(number / 0 );
} catch (Exception e) {
System.out.println("Something went wrong.");
}
}
}
Explaination
Output – “Something went wrong.”
When Number is divided by Zero , it will throw exception. That exception will be catched by Catch Statement and , “Something went wrong.” will be limited.