Week 11 Flashcards
An abnormal conditon or an error that disrupts the normal flow of a program
An exception
Allows the program to continue executing after an exception occurs
Exception handling
Common examples of exceptions
Out of range array indices, arithmetic overflow, division by 0, invalid method params
What is a synchronous error?
Errors that occur when a statement executes - typically associated with runtime errors that detected during execution (out of bounds array, division by 0)
What are asynchronous events?
They occur independently of the main program flow. They’re associated with external events, like disk I/O completions, network message arrivals, or user inputs like mouse clicks/keystrokes
Why is exception handling important from the earliest stages of design?
It’s important for robust and fault-tolerant programs. Going back and adding it later is expensive, time-consuming, and likely difficult.
What does the “throws” keyword do?
Indicate that the method may throw exception(s). When “throws” is seen it means the caller of the method has to be responsible for handling the exception, because it likely doesn’t handle any itself.
What is the purpose of the finally block?
Specifies a section of the code that MUST be executed, regardless of whether an exception is thrown or caught.
It’s typically used for cleanup or resource release operations. I.E. closing a file or releasing a DB connection
What are checked exceptions?
Exceptions that are checked at compile time. These exceptions are directly derived from the Throwable class, except for RunTImeException and Error.
Name checked exceptions
IOException, ClassNotFoundException, SQLException, SocketExceptoon, FileNotFoundException
Name unchecked exceptions
Error, RunTime Exception and all of its children (NullPointer, ClassCast, Arithmetic, DateTime, ArrayStore)
FileNotFoundException inherits from IOException, what catch clause can be used to catch a FileNotFoundException
IOException
When does a method terminate and not return a value?
When it throws an exception
What happens to local variables when a method throws an exception but does not catch it in scope
They go out of scope, the method-call stack is “unwound”
What is stack unwinding?
When an exception is thrown but not caught in a particular scope the method-call stack is “unwound”