CCEA A-Level Software Systems Development CL4
Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures
Exception Handling and Managing Input and Output
Testing an Object Oriented Application
Graphical User Interface Objects and Events
Multiple Forms and Linking to Files
Designing, Testing and Evaluating an Event Driven Application
Reasons for Systems Development and Systems Methodologies
Managing Projects
Testing Strategies
Database Concepts and Entity Relationship Modelling
Normalisation and Structured Query Language
Project Management and the Systems Approach in Practice
Defining Requirements and Documenting the Design
Building a Desktop Solution with a Database
Testing and Evaluating the Solution
Designing, Testing and Evaluating an Event Driven Application
Using try and catch inside an event handler
- 3 things to know
- AS Unit 2
Overview
Catching a failure raised by what the user typed, reporting it in a message box rather than to a console, closing anything the handler opened, and the state the form is left in.
What you need to know
Answer each one before you reveal it.
What does a catch block do?
What is a finally block for?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What does a try block contain?
Model answer
A try block contains the statements that might fail, and the runtime watches them so a fault raised inside is passed to the matching catch.
- 2
What does a catch block do?
Model answer
A catch block receives an exception of a stated type and holds the code that deals with it, and execution then continues after the block.
- 3
What is a finally block for?
Model answer
A finally block runs whether or not an exception occurred, so a file or connection opened in the try is closed exactly once.
- 4
A click handler contains try { int n = Integer.parseInt(txtQty.getText()); lbl.setText("Ordered " + n); } catch (NumberFormatException ex) { lbl.setText("Enter a whole number"); } and the user types 5 then clicks. What does the label read?
Model answer
The label reads Ordered 5, because parseInt converts the characters successfully, the setText line runs, and the catch block is skipped.
- 5
The handler try { int n = Integer.parseInt(txtQty.getText()); lbl.setText("Ordered " + n); } catch (NumberFormatException ex) { lbl.setText("Enter a whole number"); } runs while the box holds the word two. What does the label read?
Model answer
The label reads Enter a whole number, because parseInt throws, the setText line inside the try is never reached, and the catch block runs instead.
- 6
Why should a catch block name a specific exception type rather than catch every exception?
Model answer
Naming a specific type deals only with the fault expected there, so a different and unforeseen fault is not hidden behind the wrong message.
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.
Every question in Designing, Testing and Evaluating an Event Driven Application, 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.