Example to throw ArithmeticException in Java

This article discuss what is an arithmetic exception and the why it occurs. Here you'll also learn how to handle such kind of exceptions using example.

Example to throw Arithmetic Exception in Java

Arithmetic Exception is a kind of unchecked error in Java and these kind of exception occurs, when you divide a number by zero or if there is a mathematical or calculation errors that occurs at the RunTime.

java.lang.ArithmeticException is the base class of arithmetic exceptions that extends Runtime Exception.

See the example given below.

Syntax of Arithmetic Exception:

public ArithmeticException()
You can also write an ArithmeticException with the specified detail message, such as:
public ArithmeticException(String s)
Arithmetic Exception Example:
public class StringTest {
public static void divide() throws ArithmeticException {
int x = 10, y = 0;
int z = x / y;
public static void main(String[] args) {

Output of the Exception:

Exception in thread "main" java.lang.ArithmeticException: / by zero

Share on Google+Share on Google+

Example to throw ArithmeticException in Java

Posted on: October 2, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Example to throw ArithmeticException in Java  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image