Programmers learn & share
0 votes

Problem :

I got bellow message from my code

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

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 (36.1k points)  
edited by
2,183 questions
2,490 answers
241 users