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
Exception Handling and Managing Input and Output
The finally block and releasing resources
- 3 things to know
- AS Unit 1
Overview
Finally block and resource leak.
What you need to know
Answer each one before you reveal it.
Why might closing a file itself need to be inside a try block?
What is a finally block normally used for?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is a finally block?
Model answer
A finally block is written after the catch blocks and its statements run whether or not an exception was thrown, so it holds work that must happen either way.
- 2
What is a finally block normally used for?
Model answer
A finally block normally releases resources, closing an open file, a database connection or a network socket, so nothing is left held after the method finishes.
- 3
Does a finally block run when no exception occurs?
Model answer
The finally block runs after the try block has completed normally, just as it runs after a catch block has dealt with a fault.
- 4
Does a finally block run when the exception is not caught at all?
Model answer
The finally block still runs as the method is abandoned, so the clean-up happens before the exception travels out to the calling method.
- 5
Does a finally block run when the try block executes a return?
Model answer
The finally block runs before the method actually returns, so a value on its way back to the caller does not allow the clean-up to be skipped.
- 6
A program runs try { System.out.println("1"); throw new Exception(); } catch (Exception e) { System.out.println("2"); } finally { System.out.println("3"); } and then System.out.println("4");. What is printed?
Model answer
The try prints 1 and then throws, so the handler prints 2, the finally prints 3 because it always runs, and execution continues to print 4, giving 1, 2, 3 and 4.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
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.