• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/12

Click to flip

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.

It is created by the JVM when an abnormal situation arises in your program.

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
Two of its main subclasses

Error and Exception

Continue for more on those

Exceptions class hierarchy - Error
Three of its main subclasses

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

Checked Exception: Java does force the coder to write some 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

Declare:
Use the "throws" keyword in the header of the method that contains the offending code.

Catch: Use try and catch blocks in the program code if it is capable of throwing such an exception

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.