Handling Exceptions Flashcards

1
Q

True/false: A try block must be accompanied by either a catch block or a finally block or both.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True/false A catch must have a exception: catch(SomeException se){ }

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True/false: There can be anything between a catch or a finally block and the closing brace of the previous try or catch block.

A

False

- There cannot be any thing between a catch or a finally block and the closing brace of the previous try or catch block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True/false: You can have any number of catch blocks in any order.

A

True

- but each catch must be of a different type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True/false: A catch for a subclass exception should occur before a catch block for the superclass exception.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True/false: Finally cannot occur before any catch block.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of these statements are true:

  1. If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
  2. An overriding method must declare that it throws the same exception classes as the method it overrides.
  3. The main method of a program can declare that it throws checked exceptions.
  4. A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
  5. finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
A

3, 4
- Normal execution will not resume if an exception is uncaught by a method. The exception will propagate up the method invocation stack until some method handles it. If no one handles it then the exception will be handled by the JVM and the JVM will terminated that thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Which of these represents runtimeExceptions.
1. RuntimeException
2. CheckedException
3. NullPointerException
4. ArrayIndexOutOfBoundsException
5. CompilationException
6. Throwable
7. StackOverflowException
8. MemoryOutOfBoundsException
9. IllegalArgumentException
10 NumberException
A

1, 3, 4, 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True/false: If a checked exception is thrown inside a catch it must be be handles by either a try catch block or declared in the throws clause of the enclosing method.

A

True

- Also true for any other method that throws a checked exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can be the type of a catch argument::

  1. Any class that extends java.lang.Exception
  2. Any class that extends java.lang.Exception except any class that extends java.lang.RuntimeException
  3. Any class that is-a Throwable.
  4. Any Object
  5. Any class that extends Error
A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of these statements are true:

  1. If a RuntimeException is not caught, the method will terminate and normal execution of the thread will resume.
  2. An overriding method must declare that it throws the same exception classes as the method it overrides.
  3. The main method of a program can declare that it throws checked exceptions.
  4. A method declaring that it throws a certain exception class may throw instances of any subclass of that exception class.
  5. finally blocks are executed if and only if an exception gets thrown while inside the corresponding try block.
A

3, 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly