Unit 7: Exeptions Flashcards

1
Q

What is an “exception” in Java?

A

An event that occurs during the execution of a program that disrupts the normal flow, like a file not found or invalid number input.

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

Give examples of common exceptions in Java.

A

FileNotFoundException

ArrayIndexOutOfBoundsException

NumberFormatException

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

What happens if an exception is not handled?

A

The JVM reports the exception and skips to the next event — the program may miss actions or become unreliable.

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

Why should we handle exceptions instead of ignoring them?

A

To avoid crashes, ugly error messages, or continuing with unreliable/partial data — important in professional software.

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

What is the basic structure for handling exceptions in Java?

A

try {
// risky code
} catch (ExceptionType e) {
// handle it
}

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

When does the catch block run?

A

Only if an exception is thrown in the try block — otherwise, it’s skipped.

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

Why not always check for errors before running risky code?

A

Sometimes it’s hard or impossible to predict if an error will happen — using try-catch is more reliable.

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