Exceptions&IO Flashcards

1
Q

What is an exception handler?

A

A section of code that gracefully responds to exceptions.

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

What is a default exception handler?

A

Deals with unhandled exceptions, prints an error message, crashes the program.

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

How do you handle an exception?

A

try
{ (try block statements…)
}
catch (ExceptionType ParameterName)
{ (catch block statements…)
}

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

How do you handle multiple exceptions?

A

● The code in the try block may be capable of throwing more than one type of
exception.
● A catch clause needs to be written for each type of exception that could
potentially be thrown.
● The JVM will run the first compatible catch clause found.
● The catch clauses must be listed from most specific to most general.
● For a given thrown exception, only one catch block will be executed. Your logic
should not be spread across multiple catch blocks.

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

What is a finally block?

A

A block may be used to specify code that will be
executed last, whether the code in a try block causes an exception or not.
The code in a finally block is always executed, even if an exception is rethrown.

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

What is a custom exception?

A

Custom exceptions usually define one or
more constructors to accept a detailed error
message, another Throwable (the root
cause), or both.

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