Exceptions Flashcards

1
Q

What is the difference between final, finalize(), and finally?

A

Final is a keyword that prevents any changes from being made to the variable/method/class attached to it

finalize() is a method that is used to perform cleanup before the garbage is collected

Finally is a block in exception handling that will always run regardless of exceptions

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

Explain throw, throws, Throwable

A

throw is a keyword that is used to throw an exception manually

throws is a keyword which is used in the method signature to indicate that a method may need to throw that exception

Throwable is a super class for all types of errors and exceptions. If you want to create your own exception, it must extend this class

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

Do you need a catch block? Can you have more than one? Is there any order to follow?

A

You do not need catch block after a try statement as long as you have a finally block

There can be multiple catch blocks, but only one will be executed at a time

Each catch block must have a different exception handler

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

What is the base class of all exceptions? What interface do they all implement?

A

Throwable is the base class of all exceptions, and they all implement the Serializable interface

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

List some checked and unchecked exceptions

A

Checked: IOException, ClassNotFoundException, FileNotFoundException

Unchecked: ArithmeticException, ArrayIndexOutOfBounds

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