Week 11 - Exceptions and Unit Testing Flashcards

1
Q

What does an exception do?

A

It disrupts the normal flow of the program’s instructions during execution.

When an exceptional situation arises, an object representing that exception is thrown, and the normal flow of the program is interrupted.

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

What are checked exceptions?

A

These are exceptions that the Java compiler forces you to handle, either by using a try-catch block or by specifying in the method signature.

IOException, SQLException, FileNotFoundException

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

What are unchecked exceptions?

(Runtime exceptions)

A

These are exceptions that the compiler does not require you to handle explicitly. They typically represent programming errors.

NullPointerException, ArrayIndexOutOfBoundsExcept, ArithmeticException

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

What exception will this line of code give?
int number = Integer.parseInt(“myint”);

A

Number Format Exception

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

What mechanism are we using to handle exceptions?

A

try catch block

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

What are two types of Throwable?

A

Error and exception.

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

OutOfMemoryError and StackOverflowError are which type of Throwables?

A

Errors.

Who’d have thought?

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

What happens when the exception is not handled immediately?

A

It is passed to the method that called the method that threw the exception. We refer to this as the call stack. The exception goes up in the call stack until it is eventually handled by the try-catch block

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

What is a unit test?

A

Unit Testing is a type of software testing where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected.
Unit Testing is done during the development (coding phase) of an application by the developers.
Unit Tests isolate a section of code and verify its correctness. A unit, in the OOP sense may be an **individual function, method, procedure, module, or object. Should be one-purpose test. Always void return type, and methods shouldn’t be public. **

bolded is a potential question (multiple choice).

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