1 00:00:00,380 --> 00:00:02,060 - [Instructor] In this and the next several videos, 2 00:00:02,060 --> 00:00:05,070 we're going to be talking about handling exceptions 3 00:00:05,070 --> 00:00:06,220 in Python. 4 00:00:06,220 --> 00:00:10,360 So far, when we've had runtime problems in our code, 5 00:00:10,360 --> 00:00:14,640 we've simply seen tracebacks appear either in Ipython 6 00:00:15,522 --> 00:00:19,350 or at the command line when we were running a Python script. 7 00:00:19,350 --> 00:00:23,600 However it is possible to write code that can look 8 00:00:23,600 --> 00:00:27,370 at problems that occur and then deal with those problems. 9 00:00:27,370 --> 00:00:29,310 Now in the context of file processing, 10 00:00:29,310 --> 00:00:32,480 there happen to be a number of potential exceptions 11 00:00:32,480 --> 00:00:33,530 that can occur. 12 00:00:33,530 --> 00:00:36,850 So, for example, if I try to open up a file 13 00:00:36,850 --> 00:00:40,830 that does not exist, so that I can read from that file, 14 00:00:40,830 --> 00:00:43,354 I'll wind up with a file not found error, 15 00:00:43,354 --> 00:00:47,120 or if I try to open a file for reading 16 00:00:47,120 --> 00:00:50,030 that's in a folder that I don't have access to, 17 00:00:50,030 --> 00:00:52,265 or I try to write a file into a folder 18 00:00:52,265 --> 00:00:54,290 that I don't have access to, 19 00:00:54,290 --> 00:00:55,970 I'll get a permissions error. 20 00:00:55,970 --> 00:00:58,870 And if I try to write to a file object 21 00:00:58,870 --> 00:01:00,500 that's already been closed, 22 00:01:00,500 --> 00:01:02,500 I'll get a value error. 23 00:01:02,500 --> 00:01:06,370 So what we wanna do over the next several videos 24 00:01:06,370 --> 00:01:09,300 is talk about how we can write code 25 00:01:09,300 --> 00:01:12,350 that's capable of dealing with exceptions. 26 00:01:12,350 --> 00:01:15,260 And we'll start by revisiting the concept 27 00:01:15,260 --> 00:01:17,290 of an exception in the first place, 28 00:01:17,290 --> 00:01:21,140 and then show you the code that can be used to deal 29 00:01:21,140 --> 00:01:22,993 with problems as they occur.