Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

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

  • 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

  • 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.
Jump to other topics
1

Introduction to Python

2

Data Structures

2.1

Lists & Strings

2.2

File Handling

3

Modularity

3.1

Subroutines

3.2

Data Flow

4

Good Practice

4.1

Naming & Whitespace

4.2

Comments

4.3

Exceptions

Practice questions on Exceptions

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
Answer all questions on Exceptions

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium