Week 11 Flashcards

1
Q

An abnormal conditon or an error that disrupts the normal flow of a program

A

An exception

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

Allows the program to continue executing after an exception occurs

A

Exception handling

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

Common examples of exceptions

A

Out of range array indices, arithmetic overflow, division by 0, invalid method params

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

What is a synchronous error?

A

Errors that occur when a statement executes - typically associated with runtime errors that detected during execution (out of bounds array, division by 0)

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

What are asynchronous events?

A

They occur independently of the main program flow. They’re associated with external events, like disk I/O completions, network message arrivals, or user inputs like mouse clicks/keystrokes

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

Why is exception handling important from the earliest stages of design?

A

It’s important for robust and fault-tolerant programs. Going back and adding it later is expensive, time-consuming, and likely difficult.

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

What does the “throws” keyword do?

A

Indicate that the method may throw exception(s). When “throws” is seen it means the caller of the method has to be responsible for handling the exception, because it likely doesn’t handle any itself.

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

What is the purpose of the finally block?

A

Specifies a section of the code that MUST be executed, regardless of whether an exception is thrown or caught.

It’s typically used for cleanup or resource release operations. I.E. closing a file or releasing a DB connection

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

What are checked exceptions?

A

Exceptions that are checked at compile time. These exceptions are directly derived from the Throwable class, except for RunTImeException and Error.

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

Name checked exceptions

A

IOException, ClassNotFoundException, SQLException, SocketExceptoon, FileNotFoundException

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

Name unchecked exceptions

A

Error, RunTime Exception and all of its children (NullPointer, ClassCast, Arithmetic, DateTime, ArrayStore)

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

FileNotFoundException inherits from IOException, what catch clause can be used to catch a FileNotFoundException

A

IOException

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

When does a method terminate and not return a value?

A

When it throws an exception

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

What happens to local variables when a method throws an exception but does not catch it in scope

A

They go out of scope, the method-call stack is “unwound”

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

What is stack unwinding?

A

When an exception is thrown but not caught in a particular scope the method-call stack is “unwound”

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

What happens after stack unwinding?

A

Attempt to catch the exception the next outer try block

17
Q

What is unique about printStackTrace and getStackTrace? (both methods of Java’s “Throwable” Class). Why is this sometimes a problem?

A

They process the entire method-call stack. When debugging this can be inefficient

18
Q

If a catch block throws a new exception, what happens to the original exception?

A

The exception and stack trace are lost

19
Q

What allows an exception object to maintain the complete stack-trace info from the original exception?

A

Chained exceptions

20
Q

How do you get the throwable method that initially caused the exception?

A

By calling the “Throwable” method getCause()