Source: https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-3-1-exceptions

[Revision notes](https://senecalearning.com/en-gb/revision-notes.md) › [GCSE](https://senecalearning.com/en-gb/revision-notes/gcse.md) › [Coding](https://senecalearning.com/en-gb/revision-notes/gcse/coding.md) › [National Curriculum](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum.md) › Exceptions

# Exceptions

Coding: Introduction to Python v3, topic 4.3.1

## Exceptions

Rather than leaving the program to crash when an error occurs, exceptions give us a chance to handle the error more gracefully.

### Exceptions

![Exceptions](https://image-v2.cdn.app.senecalearning.com/2018-08/71bff775-2bde-478f-a20c-e37e65a6a92a/exception-writing-pen-.jpg)

- When an error arises in a program, the program is said to 'throw' an exception.
- An exception is a description of the error that arose.
- Exceptions can be 'caught' or handled rather than allowing the program to crash.

### Handling exceptions

![Handling exceptions](https://image-v2.cdn.app.senecalearning.com/2018-08/5d2afec2-aaf2-46a8-ab06-593c34f9d25d/Exception-writing-keyboard-.jpg)

- If an exception can be dealt with internally, then we can catch the exception and continue with the program.
- This is done using a structure as below:
 - try: ---
 - except: ---
- The code within the try block will be executed.
 - If an exception is thrown inside the try block,  then the except block will be run to 'clean up' after the exception.

## Test yourself on Exceptions

- What is it called when an error arises in a program?
- What is the purpose of the 'except' block of a try-except structure?

[Practise this topic for free](https://app.senecalearning.com/classroom/course/72d0364c-db0a-4630-8e0a-61f48cae0252/section/d2bd7a7b-c2b9-46a1-b7a3-867fa7c06b38/session)

- Previous topic: [4.2.1 Comments](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-2-1-comments.md)

## Coding: Introduction to Python v3 contents

### 1 Introduction to Python
- 1.1 Python
  - [1.1.1 Python](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-1-1-python.md)
- 1.2 Input & Output
  - [1.2.1 Input & Output](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-2-1-input-and-output.md)
- 1.3 Data Types
  - [1.3.1 Data Types](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-3-1-data-types.md)
- 1.4 Variables & Constants
  - [1.4.1 Variables & Constants](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-4-1-variables-and-constants.md)
- 1.5 Operators
  - [1.5.1 Arithmetic & Relational Operators](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-1-arithmetic-and-relational-operators.md)
  - [1.5.2 Boolean & Assignment Operators 2](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-2-boolean-and-assignment-operators-2.md)
- 1.6 Program Flow
  - [1.6.1 Selection](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-1-selection.md)
  - [1.6.2 Iteration](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-2-iteration.md)

### 2 Data Structures
- 2.1 Lists & Strings
  - [2.1.1 Lists](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-1-lists.md)
  - [2.1.2 Strings](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-2-strings.md)
- 2.2 File Handling
  - [2.2.1 File Handling](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-2-1-file-handling.md)

### 3 Modularity
- 3.1 Subroutines
  - [3.1.1 Subroutines](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-1-1-subroutines.md)
- 3.2 Data Flow
  - [3.2.1 Data Flow](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-2-1-data-flow.md)

### 4 Good Practice
- 4.1 Naming & Whitespace
  - [4.1.1 Identifiers](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-1-identifiers.md)
  - [4.1.2 Whitespace](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-2-whitespace.md)
- 4.2 Comments
  - [4.2.1 Comments](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-2-1-comments.md)
- 4.3 Exceptions
  - [4.3.1 Exceptions](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-3-1-exceptions.md)
