Errors and Exceptions Flashcards

1
Q

What is the difference between errors and exceptions?

A

An error is something that you cannot handle.

An exception is something that you can handle by using a try-catch block

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

What are the two types of exceptions?

A

Checked

Unchecked

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

What is a checked exception?

A

An exception that is detected by the compiler and is required to be fixed with a try-catch block before running the program.

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

What is an unchecked exception?

A

An exception that is detected during runtime and is a result of bad programming by the programmer. Can be dealt with by using try-catch blocks or by finding the problem in the code.

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

What is a try-catch block?

A

A block of code used to try and deal with exceptions

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

How does a try-catch block work?

A

The first line of code in the try block runs the block inside of the try. If the try block works, then the code will skip the catch block and continue.
If it doesn’t then the catch block will be checked. If the catch block has the correct exception defined, then the catch block will deal with the exception. If it does not, then the program will end

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

What is a try-catch-finally block?

A

The same as a try-catch block but contains a finally block that will run no matter what.

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