Errors and Exceptions Flashcards
What is the difference between errors and exceptions?
An error is something that you cannot handle.
An exception is something that you can handle by using a try-catch block
What are the two types of exceptions?
Checked
Unchecked
What is a checked exception?
An exception that is detected by the compiler and is required to be fixed with a try-catch block before running the program.
What is an unchecked exception?
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.
What is a try-catch block?
A block of code used to try and deal with exceptions
How does a try-catch block work?
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
What is a try-catch-finally block?
The same as a try-catch block but contains a finally block that will run no matter what.