Exceptions and Error Types
A Java shipping program stops and prints this stack trace, a diagnostic report showing the exception and the method calls active when it occurred. Match each report component to its meaning in this example.
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Shipping.average(Shipping.java:18)
at Shipping.main(Shipping.java:7)Shipping.average was executing line 18 when the failure occurred.
/ by zero describes the arithmetic operation that failed.
ArithmeticException identifies the class of runtime failure.
Shipping.main invoked the calculation from line 7.
Caller frame
Detail message
Throw-site frame
Exception type
Each numbered Java statement group below runs on its own inside a fresh main method with no exception handling. For each one, type the simple class name of the runtime exception it throws, such as ArithmeticException, or type none if it runs without throwing an exception.
- int x = Integer.parseInt("12.5");
- String name = null; int n = name.length();
- int d = 0; int q = 7 / d;
- double r = 7.0 / 0;
- String w = "code"; char c = w.charAt(4);
- Object o = "hi"; Integer k = (Integer) o;
| Statement | Exception thrown |
| Statement 1 | |
| Statement 2 | |
| Statement 3 | |
| Statement 4 | |
| Statement 5 | |
| Statement 6 |