Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
12 Cards in this Set
- Front
- Back
What exactly is an exception, and how does it originate? |
An exception is an object that signals that an error of some kind has occurred in your program, and bad things will happen to your program if you don't deal with it. |
|
What is the benefit of having a problem signaled by exception? |
It separates the code that deals with errors (the exception handling code) from the code that is executed when things are running smoothly. |
|
What is the type of information stored in an exception object? |
The exception object has data members that store information about the nature of the problem. |
|
Exceptions class hierarchy - Throwable |
Error and Exception |
|
Exceptions class hierarchy - Error |
Error: All exceptions defined here and its subclasses all represent conditions that you as a coder are not expected to do anything about. Like ThreadDeath (so metal), LinkageError, VirtualMachineError. Known as Unchecked Exceptions. |
|
Exceptions class hierarchy - Exception and its main subclasses |
Exception: All exceptions defined here and its subclasses all represent conditions that you as a coder CAN do something about. Like ArithmeticException, IndexOutOfBounds, NegativeArraySize, NullPointer, ArrayStore, ClassCast, IllegalArgument, Security. Known as Checked Exceptions |
|
Summary: Checked vs. Unchecked exceptions |
Unchecked Exception: Java does not force you to write any code to deal with it |
|
What two options do we have as coders, and straight up gangstas, have for dealing with checked exceptions? |
Declare or Catch |
|
Where in a program would one place a throws clause? |
In the method declaration header of the method that contains the code that could cause the problem. |
|
How would we use a try catch block to handle exceptions? |
Within the method around the code itself that is capable of throwing said exception. |
|
How would we set up the order of the exceptions being handled in multiple try blocks if the exceptions are related by inheritance? |
Make sure the most abstract (or highest in the inheritance hierarchy) exceptions go at the bottom of the list of the catch blocks. (Most commonly the Exception class) |
|
What's the deal with the finally block and the code that is placed there? |
This code always runs, even if no exceptions are thrown. It is code to be executed after the try block code, usually to close streams or connections. |