thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

DevOps & Automation · Foundational

Exception Handling

Managing runtime errors in code with constructs such as try, except, else, and finally in Python.

Definition

Catching specific exceptions (requests.exceptions.Timeout, KeyError) allows retries, logging, and clean failure. finally runs regardless, for cleanup such as closing sessions. raise rethrows or creates exceptions.

Example

try: r = requests.get(url, timeout=5); r.raise_for_status() except requests.HTTPError as e: log.error(e)

Exam tip

Avoid bare except:; catch specific exceptions. else runs only if no exception occurred.

Related terms