levo

Exception Handling and Managing Input and Output

Catching more than one kind of exception

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

Overview

Several catch blocks against one try, why the order matters, why a general handler placed first makes the ones after it unreachable, and the finally block that runs either way.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Why might a single try block need several catch blocks?

Key term

In what order are catch blocks considered?

Key term

How many catch blocks run for a single exception?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Why might a single try block need several catch blocks?

    Model answer

    One group of statements can fail in more than one way, and each kind of fault may need a different response, so a separate catch block is written for each type.

  2. 2

    In what order are catch blocks considered?

    Model answer

    Catch blocks are considered in the order they are written, and the first whose type matches the exception thrown is the one that runs.

  3. 3

    How many catch blocks run for a single exception?

    Model answer

    Exactly one catch block runs, and control then passes to the code after the whole construct rather than to the remaining blocks.

  4. 4

    Why must the most specific exception type be caught first?

    Model answer

    A handler for a general type also matches every specific type beneath it, so putting the general one first would intercept the specific faults and the later blocks could never be reached.

  5. 5

    What does the compiler report if a general exception type is caught before a specific one?

    Model answer

    The compiler reports the later block as unreachable code, because no exception could ever arrive at it.

  6. 6

    A try block may throw either a number format exception or an arithmetic exception, and the catch blocks are written in that order. Which runs when the user types the word five?

    Model answer

    The word five cannot be converted to a number, so a number format exception is thrown, the first handler runs and the arithmetic handler is skipped entirely.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Exception Handling and Managing Input and Output, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.