Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR TEMPLATE] Java - ArithmeticException #28

Open
4 tasks done
nedpals opened this issue Nov 3, 2023 · 2 comments
Open
4 tasks done

[ERROR TEMPLATE] Java - ArithmeticException #28

nedpals opened this issue Nov 3, 2023 · 2 comments

Comments

@nedpals
Copy link
Owner

nedpals commented Nov 3, 2023

Name Type Code Language
ArithmeticException Runtime Exception java.lang.ArithmeticException Java

Description

Generic arithmetic error, like division by zero or an overflow.

Sample Code

public class Arith {
	public static void main(String[] args) {
		double out = 3 / 0;
		System.out.println(out);
	}
}

Sample Error Message

Exception in thread "main" java.lang.ArithmeticException: / by zero
    at Arith.main(Arith.java:3)

Implementation Checklist

  • Implemented analysis
  • Implemented explanation translation
  • Implemented bug fix generation
  • Add tests
@nedpals
Copy link
Owner Author

nedpals commented Nov 7, 2023

Name Type Code Language
ArithmeticException Runtime Exception java.lang.ArithmeticException Java

Description

Occurs when the result of a division is recurring (never ending), and we haven't specified rounding mode/scale. In other words, BigDecimal won't know how to represent a recurring division result if we haven't specified to what decimal places the result should be rounded, so it throws this exception.

https://www.logicbig.com/how-to/code-snippets/jcode-java-exception-arithmeticexception-no-exact-representable-error.html

Sample Code

import java.math.BigDecimal;

public class ArithEx {
    public static void main(String[] args) {
        BigDecimal a = new BigDecimal(5);
        BigDecimal b = new BigDecimal(3);
        BigDecimal result = a.divide(b);
        System.out.println(result);
    }
}

Sample Error Message

Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        at java.base/java.math.BigDecimal.divide(BigDecimal.java:1722)
        at ArithEx.main(ArithEx.java:7)

Implementation Checklist

  • Implemented analysis
  • Implemented explanation translation
  • Implemented bug fix generation
  • Add tests

@nedpals
Copy link
Owner Author

nedpals commented Dec 12, 2023

UPDATE: Lacking BigInt stub support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

1 participant