Java Exception Handling Quiz
A quiz covering Java exception handling, applets, and core Java programming concepts
Questions
Identify the true statements.
- Checked exceptions must be explicitly caught or propagated(declared Thrown)
- Unchecked exceptions must be explicitly caught or propagated(declared Thrown)
- Checked exceptions in Java extend the java.lang.Exception class
- Unchecked exceptions extend the java.lang.RuntimeException class
By convention, all exception-class names should end with the word Exception
- True
- False
Java guarantees that a finally clause (if one is present) will execute even if a try block exits by using a return, break or continue statement.
- True
- False
From which problems is it possible for a program to recover?
- Errors
- Exceptions
- Both errors and exceptions
- Neither
Is a program required to catch all exceptions that might happen?
- No. You can write a program to catch just the exceptions you want.
- No. But if a program catches one type of exception it must catch all other types as well.
- Yes. If a program is not written to catch all exceptions it will not compile.
- Yes. A program can not do I/O unless it catches all exceptions.
Class Exception is the superclass of all exceptions
- True
- False
Java throws ------------------- when division by zero in integer arithmetic occurs
- an IntegerArithmeticException
- an ArithmeticException
- a DivideByZeroException
- a NumberFormatException
A try block must always be followed by one or more catch blocks
- True
- False
If a catch handler is written to catch exception objects of a superclass type, it can also catch all objects of that class's subclasses.
- True
- False
What type of exception is thrown by parseInt() if it gets illegal data?
- ArithmeticException
- RunTimeException
- NumberFormatException
- NumberError
Is this Legal? Class ExceptionA extends Exception {} class ExceptionB extends ExceptionA {} public class Test{ void thrower() throws ExceptionA{ throw new ExceptionA(); } public static void main(String[] args){ Test t = new Test(); try{t.thrower();} catch(ExceptionB e) {} } }
- True
- False
Which statement is FALSE about the try{} block?
- Some of the statements in a try{} block will never throw an exception.
- The statements in a try{} block may throw several types of exception.
- The try{} block can not contain loops or branches.
- The try{} block must appear before the catch{} blocks.
Which statement is FALSE about catch{} blocks?
- There can be several catch{} blocks in a try/catch structure.
- The catch{} block for a child exception class must PRECEED that of a parent execption class.
- The catch{} block for a child exception class must FOLLOW that of a parent execption class.
- If there is no catch{} block there must be a finally{} block.
What happens in a method if an exception is thrown in a try{} block and there is NO MATCHING catch{} block?
- This is not legal, so the program will not compile.
- The method throws the exception to its caller if there were no matching catch{} block.
- The program halts immediately.
- The program ignores the exception.
How many finally{} blocks may there be in a try/catch structure?
- There must always be one, following the last catch{} block.
- There can be zero or one immediately after each catch{} block.
- There can be zero or one, following the last catch{} block.
- There can be any number, following the last catch{} block.
When is a finally{} block executed?
- Only when an unhandled exception is thrown in a try{} block.
- Only when any exception is thrown in a try{} block.
- Always after execution has left a try{} block, no matter for what reason.
- Always just as a method is about to finish.
What is Java (in regard to Computer Science) ?
- A type of coffee
- An object-oriented programming language
- An interactive website
- None of the above
What is an Applet ?
- Type of computer
- A Java program that is run through a web browser
- An interactive website
- A type of fruit
Java runs on _______.
- Windows
- Unix/Linux
- Mac
- All of the Above
Why can't the whole program just consist of the one line that does the painting ?
- In Java, to create an applet, you can't call on functions without defining a class to call them.
- To appear on the web, Java must use an applet, and without first defining a class, you won't be painting onto anything.
- The drawString function is not defined without the "import" statements at the top.
- All of the above.