There are times when it makes sense for a program to deliberately throw an exception. This is the case when the program discovers some sort of exceptional or error condition, but there is no reasonable way to handle the error at the point where the problem is discovered. The program can throw an exception in the hope that some other part of the program will catch and handle the exception.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
It's usually a good idea to throw a NullPointerException for null inputs.Rob Prime wrote: . . . will throw NullPointerException if name == null . . .
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Yes, he doesRob Prime wrote:I think Campbell means this: . . .
java.lang.ArithmeticException: / by zero
at exceptionthrows.ExceptionDemo.divideByZeroAndPrint(ExceptionDemo.java:22)
at exceptionthrows.Main.main(Main.java:19)
java.lang.ArithmeticException: / by zero
BUILD SUCCESSFUL (total time: 0 seconds)
I can't see what is wrong with it. Have you saved and recompiled your Java code before execution?java ExceptionDemo
Exception in thread "main" java.lang.ArithmeticException: Integer division by 0
at ExceptionDemo.divideByZeroAndPrint(ExceptionDemo.java:12)
at ExceptionDemo.main(ExceptionDemo.java:21)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |