In order to define a method that could generate an exception what keyword must you include in the method declaration? A) static B) void C) buggy D) throws E) none of the above
In order to generate an exception you can use what Java keyword? A) runwindowsrun B) throws C) error D) throw E) none of the above
In order to retrieve the error message from any object of type exception (or any that inherits exception) you can use the following method built into the exception class A) getMessage B) get C) toString D) showmethemoney E) none of the above
If you are attempting to catch an error when it occurs, you must enclose statements that may generate an exception in the following clause A) throws B) try C) on error goto D) help_me_obi_wan_kenobi_you're_our_only_hope E) none of the above
If you try to access an element of an array that does not exist you generate what sort of exception? A) ArtithmeticException B) AreYouIllingMeException C) IndexOutOfBoundsException D) ClassCastException E) none of the above
File Input/Output exceptions can be handled by a catch clause that handles which of the following Exception type A) IOException B) NumberFormatException C) Int19hException D) NullPointerException E) none of the above
What class provides the readLine() method used to help read input from files (or other media)? A) readstuff B) fileReader C) BufferedReader D) buffin E) none of the above
On your answer sheet write down T if the statement is true, F if it false
You can have multiple try clauses for every catch clause.
If you call readLine() multiple times on the same file, you will always get the same result each time.
In order to read from files, you need to import java.inputoutput.*;
If you have a catch clause of type Exception, you automatically handle all possible Exceptions known to Java
Double.parseDouble could throw an exception of type NumberFormatException
When the readLine() method returns null, it means that the file that is opened is too big for Java to handle.
In order to signal the end of each case for a switch clause, you need to use the Java keyword break.
“I'll handle this ... the only danger in space is if we land on the terrible Planet of the Apes ... wait a minute. Statue of Liberty ... THAT WAS OUR PLANET! YOU MANIACS! YOU BLEW IT UP! DAMN YOU! DAMN YOU ALL TO HELL!”
The following problems require you to write code. Note: All code standards apply to the code you write. (ie: easy to read, well commented, well indented, etc) You will have points marked off if it does not meet the standards.
Assuming you have a file opened in a FileReader object called frank, write code that will read and print every single line in the file (print using System.out.println()) Make sure you have some exception recovery code. (Worth 3 points)
You have a method called dosomething(), you need to call it to do something, but it may (and probably will) generate exceptions of IOException, NumberFormatException and probably another kind of Exception type. You need to write code that calls this and prints out a different error message based on what type of Exception is generated. (you are responsible to generate different messages for a generic Exception, a NumberFormatException and an IOException) (Worth 3 points)