ArithmeticError
PHPERRORCommonMath
Base class for arithmetic errors
Quick Answer
Catch ArithmeticError as a base class to handle both DivisionByZeroError and any future arithmetic errors.
What this means
Base class for DivisionByZeroError and any arithmetic-related errors. Catch this if you want to handle all arithmetic failures in one handler.
Why it happens
- 1Caused by subclasses — typically DivisionByZeroError
- 2intdiv() called with PHP_INT_MIN and -1
Fix
Catch base class
Catch base class
try {
$r = intdiv($a, $b);
} catch (\ArithmeticError $e) {
// catches DivisionByZeroError too
$r = 0;
}Why this works
ArithmeticError is the base class, so catching it handles all arithmetic subclasses.
Code examples
intdiv overflowphp
intdiv(PHP_INT_MIN, -1); // ArithmeticError on 64-bit
Same error in other languages
Sources
Official documentation ↗
PHP Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev