levo

Exception Handling and Managing Input and Output

Checked and unchecked exceptions

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

Overview

The distinction the compiler enforces, which faults must be caught or declared, which are left to the programmer, and why an unchecked exception usually signals a fault in the code rather than in the input.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a checked exception?

Key term

Why are file operations made checked?

Key term

In Java, why are exceptions caused by programming mistakes left unchecked?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a checked exception?

    Model answer

    A checked exception is one the compiler insists is dealt with, so any method that might throw it must either catch it or declare it in a throws clause.

  2. 2

    What is an unchecked exception?

    Model answer

    An unchecked exception is one the compiler does not require to be handled, and it usually signals a programming mistake such as a bad index or a reference holding null.

  3. 3

    Give two examples of checked exceptions.

    Model answer

    A file not found exception and a general input or output exception are both checked, because no program can guarantee that a file exists or that a device will respond.

  4. 4

    Give two examples of unchecked exceptions.

    Model answer

    A null pointer exception and an array index out of bounds exception are both unchecked, because correct code should never produce either of them.

  5. 5

    Why are file operations made checked?

    Model answer

    The success of a file operation depends on the machine outside the program, so the language obliges the programmer to state what should happen when the file is missing, locked or unreadable.

  6. 6

    Why are programming mistakes left unchecked?

    Model answer

    Demanding a handler for every possible bad index would clutter almost every line of code, and the proper response to a programming mistake is to correct the code rather than to catch the fault.

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.