• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
8 views

Problem :

I got bellow message from my code

Exception in thread "main" java.lang.ArithmeticException: / by zero
by (6.9k points)  

1 Answer

0 votes

Solution :

Usually one would come across “java.lang.ArithmeticException: / by zero” when tried to divide two numbers and the number in the denominator is zero.

Handling the ArithmeticException using try-catch block.

1. Firstly Surround the statements that could throw ArithmeticException with try-catch block.

2. Catch ArithmeticException

3. When any exception occurs, the execution falls onto the catch block from the point of occurrence of exception. 

4. It executes the statement in catch block and continues with the statement present after the try-catch block. 

5. So care has to be taken while handling the exceptions.

by (20.3k points)  
edited by
...