Synopsis An arihmetic error occurred
Syntax data RunTimeException = ArithmeticException(str message);
Function data RunTimeException = ArithmeticException(str message);
Usage import Exception;
Description This error is generated when an illegal arithmetic operation occurs or when a numeric function is called with an out-of-range argument.

  • Check the validity of the argument before you call the function or apply the operator.
  • Catch the ArithmeticException yourself, see Rascal:TryCatch.
Examples Division by 0 gives an error:
|stdin:///|(2,1,<1,2>,<1,3>): ArithmeticException("/ by zero")

Giving an out-of-range argument to a mathematical function also gives an error:
rascal>import util::Math;
|rascal://util::Math|(9442,248,<503,0>,<517,28>): ArithmeticException("x should be between -(pi/2) and (pi/2)")
	at *** somewhere ***(|rascal://util::Math|(9442,248,<503,0>,<517,28>))
	at tan(|stdin:///|(5,24,<1,5>,<1,29>))

We can also catch the ArithmeticException error. First import the Rascal exceptions (which are also included in Prelude) and IO:
rascal>import Exception;
rascal>import IO;
rascal>try println(3/0); catch ArithmeticException(msg): println("The message is: <msg>");
The message is: / by zero
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit