3.1.1.9 Exception handling. Flashcards
What is an exception?
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.
What is the key word for when an exception happens?
An exception is ‘thrown’.
What does it mean to ‘catch’ an exception?
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.
What class represents all exceptions?
java.lang.Exception
What are exceptions subtypes of?
‘Throwable’`
Define ‘throwable’.
‘Throwable’ is the superclass for all types of errors and includes the error class.
Why is catching an exception bad practice?
We’re telling java, this code handles this exception type.
What is a stack trace?
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.
Outline an example of exceptions.
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.