This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The above is one of the incorrect answers to a question on Exceptions. The explanation given is that in order to use the above, java.io should be imported or the exception should be declared with a fully qualified name. What is the fully qualifed name of this exception?
IOException is located in java.io, so the fully qualified name would be java.io.IOException (and the program will compile successfully if you make that change). That is not the only thing that is fishy with this code, though.
By the way, if you're not sure where something like this is located, you can go to the Java API docs, click on "All Classes" in the top left frame, and then scroll down the list to find the item you're looking for.
Joined: May 12, 2011
Hi Kurt, thanks. I now see what that line means. The 7/x throws runtime exception. All the answer options are about declaring this exception.
There are tons of ways to work with Exceptions, and Exception types.
My favorite (And probably not the best method) is using try/catch
Generally i try to use just the simple javaException, because it will give information about ANY Exception thrown about what you are trying to do. Further down the line your programs may need to do certain things based upon what error is thrown, that is where you would want to become more specific in what Exception you want to be looking for.
This will print to your console what exception is being thrown, from there you can do a few quick google searches to find out what the problem may be. But in this case its because you are trying to divide by zero.