3.1.1.9 Exception handling. Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is an exception?

A

An exception is an event, which occurs during the execution of a program.

An unexpected event that happens and the program cannot continue normal behaviour until the problem is addressed.

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

What is the key word for when an exception happens?

A

An exception is ‘thrown’.

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

What does it mean to ‘catch’ an exception?

A

We are telling Java that our catch block code makes everything better and handles the exception.

Gives out program a chance to recover from a problem and continue normal execution.

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

What class represents all exceptions?

A

java.lang.Exception

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

What are exceptions subtypes of?

A

‘Throwable’`

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

Define ‘throwable’.

A

‘Throwable’ is the superclass for all types of errors and includes the error class.

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

Why is catching an exception bad practice?

A

We’re telling java, this code handles this exception type.

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

What is a stack trace?

A

When java hits an error, it throws an exception and exits the program.

List of the method calls that the application was in the middle of when an exception was thrown.

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

Outline an example of exceptions.

A

ArrayIndexOutOfBoundsException - Try to access an element in an an array that doesn’t exist.

ClassCastException:
- When you try to cast a class aas a type that isn't a supertype or subtype.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly