I am confused by questions such as "Which of the following exceptions are always thrown programmatically?"
So I thought this was a distinction between checked and unchecked exceptions, but it seems this isn't the case.
This was one of the qs on the practice exam from Sybex with the following options:
A - ArrayIndexOutOfBounds
B - ExceptionInInitializerError
C - java.io.IOException
D - NullPointerException
E - NumberFormatException
The answer says "All of these exceptions can be thrown programmatically, but the question asks which ones always are. An
IOException is thrown by many methods that read/write files and is always thrown programmatically. Similarly, NumberFormatException is thrown when convering numbers. The other three are thrown by the JVM"
I just can't get my head around what exactly it means by 'programmatically thrown'?
What thrown programmatically means is that the exception is the result of a statement like throw new XYZException("Something bad."); That means that methods which read numbers have throw new NumberFormatException("1234567891011121314151617"); in, or similar, and methods to read files have such throw statements for IOException. If you suffer a NullPointerException on the other hand, there may not be a throw statement anywhere.