ArithmeticException in Java — What It Means and How to Fix It

What Java's ArithmeticException means and how to fix it.

Published November 2, 2026

ArithmeticException is thrown for illegal arithmetic such as integer division by zero.

What it means and why it happens

Integer and long division or modulo by zero throw; floating-point division by zero yields Infinity or NaN instead.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
java.lang.ArithmeticException: / by zero

Practical examples

Code that triggers it

int r = 10 / 0;

The fix

int d = getDivisor();
int r = (d != 0) ? 10 / d : 0;

Floating point behaves differently

double x = 10.0 / 0;   // Infinity, no exception

Common mistakes

  • Not checking divisors.
  • Expecting doubles to throw.
  • Catching ArithmeticException broadly.

Key takeaways

  • ArithmeticException: ArithmeticException is thrown for illegal arithmetic such as integer division by zero.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Why does 10.0/0 not throw?

IEEE 754 floating point defines Infinity.

How do I find which line caused ArithmeticException?

The error message and stack trace show the file and line; start there and work backwards.

More Java articles