Week 11 - Exceptions and Unit Testing Flashcards
What does an exception do?
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.
What are checked exceptions?
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
What are unchecked exceptions?
(Runtime exceptions)
These are exceptions that the compiler does not require you to handle explicitly. They typically represent programming errors.
NullPointerException, ArrayIndexOutOfBoundsExcept, ArithmeticException
What exception will this line of code give?
int number = Integer.parseInt(“myint”);
Number Format Exception
What mechanism are we using to handle exceptions?
try catch block
What are two types of Throwable?
Error and exception.
OutOfMemoryError and StackOverflowError are which type of Throwables?
Errors.
Who’d have thought?
What happens when the exception is not handled immediately?
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
What is a unit test?
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).