Questions tagged [arithmeticexception]

An ArithmeticException is an Exception that indicates an error generated when performing a calculation.

An ArithmeticException is an Exception that indicates an error generated when performing a calculation.

A common calculation that throws this exception is trying to divide a number by zero, such as this...

double firstNumber = 10;
double secondNumber = input.readDouble();
double result = firstNumber / secondNumber;

When coding such a calculation, it is easy to overlook the fact that the user can input a zero for the secondNumber. For the vast majority of numbers, this code will run correctly, and so the programmer might overlook the potential problem.

Programmers should wrap calculation code within try-catch blocks to help catch these Exceptions, or perform validation of variables before they're used in a calculation.

64 questions
3
votes
2 answers

Java ArithmeticException BigInteger would overflow supported range

I am working on a algorithm to check if number is prime and need to work with really big numbers therefore I am using BigInteger class. Problem is that this exception is thrown ArithmeticException BigInteger would overflow supported range. Exception…
user435421
  • 859
  • 2
  • 13
  • 31
2
votes
5 answers

Java - Why the subclass of ArithmeticException class is not called?

I want to modify the ArithmeticException output message. So, for that i did few experiments. I extended the ArithmeticException class byExtenderClass class. The point of this question is not only to find the solutions to modify the…
Stack Overflow
  • 1
  • 5
  • 23
  • 51
2
votes
4 answers

try-multicatch with ExceptionInInitializerError and ArithmeticException confusion

public class HelloWorld { static { try { int i=10/0; } catch(ExceptionInInitializerError | ArithmeticException e ) { e.printStackTrace(); } } public static void main(String []args) { …
2
votes
1 answer

BigDecimal Underflow

I am trying to render a fractal called the "Lorenz Attractor" with Java. Because double does not work (values out of range), I decided to choose BigDecimals. After 38 iterations my code crashes, it gets me an ArithmeticException (Underflow). Heres…
Distjubo
  • 959
  • 6
  • 21
2
votes
2 answers

ArithmeticException in unchecked code in C#

We get an ArithmeticException (Overflow or underflow in the arithmetic operation.) in the following line on a customer machine. We are not able to reproduce it on any PC (customers or ours): var actualFullness = (byte)((hdd.Capacity - hdd.FreeSpace)…
tom.maruska
  • 1,411
  • 16
  • 22
2
votes
1 answer

Cloning Git repository throwing ArithmeticException

We're utilizing Bonobo Git Server to host some internal git repos. When attempting to check out one of our repositories we're getting this error returned: RPC Failed; result=22, HTTP code = 500 fatal: The remote end hung up unexpectedly In the…
Dave Zych
  • 21,581
  • 7
  • 51
  • 66
2
votes
1 answer

"Non-terminating decimal expansion; no exact representable decimal result" happens even when divide by 100

My java code is running on HP-UX hpdev B.11.23 U ia64 and sometimes it will produce the following exception: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. The code that causes it: BigDecimal…
Kazi Islam
  • 135
  • 1
  • 2
  • 9
2
votes
1 answer

Dividing a double by zero in Java

Possible Duplicate: Why doesn't Java throw an Exception when dividing by 0.0? Why the following statement in Java will not report an ArithmeticException? double d = 1.0/0;
siva636
  • 16,109
  • 23
  • 97
  • 135
2
votes
2 answers

Points calculated using this elliptic curve point multiplication do not lie on the curve and this class brings Arithmetic exception

I get stack on my error of point multiplication using standard projective coordinates. I don't know what i missed but the multiplied points do not lie on the curve and some times it outputs something like Arithmetic Exception: integer is not…
Clickmit Wg
  • 523
  • 2
  • 9
  • 25
1
vote
0 answers

Why doesn't Java treat explicit division by zero as a compile-time exception?

Why is explicit division By zero not considered as compile time exception in JAVA ? Example : int x =9; int y = (int)x/0; Shouldnt compiler notify me about it ? I tried running the same and finding answers to it , I am not convinced that why is that…
1
vote
0 answers

Why does the program not terminate despite exception in java?

I just created a simple JFrame form using the Netbeans GUI Builder (I'm new to Java) which performs the division of two integers as shown below: Here I attempt to divide 2 by zero Obviously, I get an Arithmetic Exception. Here is the code for the…
tachyon
  • 43
  • 1
  • 7
1
vote
1 answer

Why am I getting a System.ArithmeticException with C#'s Nuget BigInteger 1.0.7?

So, I've been learning C# and testing some simple algorithms out. I made this simple class that exposes a recursive Fibonacci number function. I use memoization (Dynamic Programming) to store previously found numbers. Here's the code: using…
1
vote
2 answers

Possible solutions to BigDecimal underflow error

I am trying to use the BigDecimal.pow(int i) with very big base and exponents, however I'm getting an ArithmeticException: Underflow error. To simply put it, the code is: BigDecimal base = BigDecimal.valueOf(2147483645.4141948); BigDecimal product =…
kkmonlee
  • 379
  • 2
  • 16
1
vote
3 answers

Catching an ArithmeticException but not handling as intended

I am kinda new with the whole catching-handling exceptions concept and I was wondering why the throws ArithmeticException doesn't produce an exception error message (in this case/by zero) on exit, but instead during compilation. Shouldn't it…
JimS
  • 349
  • 1
  • 4
  • 19
1
vote
2 answers

ArithmeticException in C# code after calling C function from dll

I have code written in C# and a DLL written in C. I'm trying to call functions from the DLL. For example, header file for DLL in C: // --------------------------------------------------------------------------- #ifndef Perspectiva_DLLUnitH #define…
Yury Kerbitskov
  • 643
  • 1
  • 7
  • 21