e-learning

Python - Try & Except

Abstract

Try/except are a construct in Python used to catch a potential exception. Sometimes things go wrong in your code! Or in someone else's code in a module. Sometimes some errors might be expected like when you try and read a user supplied file, maybe it isn't available because they've specified the wrong path.

About This Material

This is a Hands-on Tutorial from the GTN which is usable either for individual self-study, or as a teaching material in a classroom.

Questions this will address

  • How do I try to execute code, knowing it might fail?
  • What are some situations where this is important?
  • How can I write my own exceptions.

Learning Objectives

  • catch an exception
  • raise your own exception

Licence: Creative Commons Attribution 4.0 International

Keywords: Foundations of Data Science, jupyter-notebook

Target audience: Students

Resource type: e-learning

Version: 3

Status: Active

Learning objectives:

  • catch an exception
  • raise your own exception

Date modified: 2023-02-13

Date published: 2022-04-25

Authors: Bazante Sanders, Donny Vrins, Helena Rasche

Scientific topics: Software engineering


Activity log