Core Java 7: Exceptions Flashcards

(4 cards)

1
Q

Exception

A

an object representing an unexpected event which is a disruption in the normal flow of code; these events can be fixed through the process of exception handling

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

Error vs. exception

A

errors should never happen in normal running of program, indicating a serious problem has occurred, ex. StackOverflowError, OutOfMemoryError, VirtualMachineError; errors are unchecked, and program should not try to catch/handle them. Errors happen at runtime and cannot be recovered

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

Checked vs. unchecked exceptions

A

checked exceptions are verified at compile-time, ex. IOException, SQLException, ParseException. Unchecked exceptions are are exceptions in the program logic itself, and is not verified at compile-time. The exception is thrown at runtime. Ex. NullPointerException, ArrayIndexOutOfBoundsException, and IllegalArgumentException

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

Exception Handling and Defensive Programming

A

In general you want to handle exceptions with try/catch, try/catch/finally, or try-with-resources. You can also check if a value is null to guard against the NullPointerException

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