Chapter 6 Flashcards

1
Q

Checked Exceptions

A

Checked exceptions have Exception in their hierarchy but not RuntimeException. They
must be handled or declared. They can be thrown by the programmer or by the JVM.
Common runtime exceptions include the following:

FileNotFoundException Thrown programmatically when code tries to reference a fi le
that does not exist.

IOException Thrown programmatically when there’s a problem reading or writing a fi le
For the OCA exam, you only need to know that these are checked exceptions.

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

Errors

A

Errors extend the Error class. They are thrown by the JVM and should not be handled or
declared. Errors are rare, but you might see these:

ExceptionInInitializerError Thrown by the JVM when a static initializer throws
an exception and doesn’t handle it

StackOverflowError Thrown by the JVM when a method calls itself too many times
(this is called infinite recursion because the method typically calls itself without end)

NoClassDefFoundError Thrown by the JVM when a class that the code uses is available
at compile time but not runtime

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

Runtime Exceptions

A

AKA Unchecked Exceptions. Runtime exceptions extend RuntimeException. They don’t have to be handled or declared.
They can be thrown by the programmer or by the JVM. Common runtime exceptions
include the following:

ArithmeticException Thrown by the JVM when code attempts to divide by zero

ArrayIndexOutOfBoundsException Thrown by the JVM when code uses an illegal
index to access an array

ClassCastException Thrown by the JVM when an attempt is made to cast an exception to a subclass of which it is not an instance

IllegalArgumentException Thrown by the programmer to indicate that a method has
been passed an illegal or inappropriate argument

NullPointerException Thrown by the JVM when there is a null reference where an
object is required

NumberFormatException Thrown by the programmer when an attempt is made to convert a string to a numeric type but the string doesn’t have an appropriate format

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

Checked Vs. Unchecked Exceptions

A

Runtime exceptions are also known as unchecked exceptions.

A checked exception includes Exception and all subclasses that do not extend
RuntimeException. Checked exceptions tend to be more anticipated—for example, trying
to read a fi le that doesn’t exist.

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

ArithmeticException

A

Unchecked (Runtime) Exception

Thrown by the JVM when code attempts to divide by zero

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

ArrayIndexOutOfBoundsException

A

Unchecked (Runtime) Exception

Thrown by the JVM when code uses an illegal index to access an array

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

ClassCastException

A

Unchecked (Runtime) Exception

Thrown by the JVM when an attempt is made to cast an exception to a subclass of which it is not an instance

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

IllegalArgumentException

A

Unchecked (Runtime) Exception

Thrown by the programmer to indicate that a method has been passed an illegal or inappropriate argument

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

NullPointerException

A

Unchecked (Runtime) Exception

Thrown by the JVM when there is a null reference where an object is required

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

NumberFormatException

A

Unchecked (Runtime) Exception

Thrown by the programmer when an attempt is made to convert a string to a numeric type but the string doesn’t have an appropriate format

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

FileNotFoundException

A

Checked Exception

Thrown programmatically when code tries to reference a file that does not exist.

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

IOException

A

Checked Exception

Thrown programmatically when there’s a problem reading or writing a file.

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