levo

Exception Handling and Managing Input and Output

Catching more than one kind of exception

  • 3 things to know
  • AS Unit 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

See a huge jump in your memorisation

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

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.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It trains answer structure

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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