From the course: Using Python for Automation
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Automate error handling - Python Tutorial
From the course: Using Python for Automation
Automate error handling
- Welcome to the world of error handling where each bug is a puzzle waiting to be solved. In this lesson, you'll dive into the crucial aspect of programming that deals with detecting and resolving errors that occur when a program is executed. Let's explore a couple of examples for how to automate error handling in Python. Open up automate_error_handling_part1.py and automate_error_handling_part2.py from the Exercise Files folder. Let's start with automate_error_handling_part1.py. In this example, the goal is to get the user to input a number and perform a calculation with that number. However, there are two potential errors that you could get, the user might enter a non-number value or they might enter zero as the input. To handle these errors gracefully, you use a try-except block. The try block contains the code that might raise an exception. So if the user enters a value that isn't a number, a ValueError will occur. And if the user enters zero, the division operation will raise a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Read files with Python3m 12s
-
(Locked)
Write files with Python2m 49s
-
(Locked)
Use Python's command-line interface2m 19s
-
(Locked)
Organize directories with Python3m 19s
-
(Locked)
Parse data with Python6m 9s
-
(Locked)
Extract data with regular expressions2m 51s
-
(Locked)
Validate inputs with automation2m 59s
-
(Locked)
Prepare for error handling2m 43s
-
(Locked)
Automate error handling3m 57s
-
(Locked)
-
-
-
-