0
Java Exceptions
Why is it that sometimes in java I have to import the Exception class while other times it don't? Example: public static int display(int a, int b) throws ArithmeticException, IOException{ throw new ArithmeticException("Cannot divide by zero"); } here I have to import java.io.IOException but there is not a import for ArithmeticException
6 Réponses
+ 5
`ArithmeticException` is defined in `java.lang` package. `java.lang` is auto imported.
Not only `ArithmeticException` but other classes like `Integer` , `Thread`, `Math` are in `java.lang` package. So every time you need to use these classes you don't need to explicitly use imports.
https://devdocs.io/openjdk~8/java/lang/package-summary
+ 1
~ swim ~ Thank you for the answer now it makes sense :)
+ 1
🇮🇳Omkar🕉 Does this have to do with the fact that it's a runtime exception rather that a checked exception?