1 00:00:00,940 --> 00:00:03,310 - [Instructor] Before we get into actually 2 00:00:03,310 --> 00:00:06,520 dealing with exceptions that occur at run time, 3 00:00:06,520 --> 00:00:09,910 let's revisit the concept of an exception for a moment. 4 00:00:09,910 --> 00:00:14,020 So first, for example, let's try division by zero 5 00:00:14,020 --> 00:00:16,760 which we demonstrated in an earlier lesson. 6 00:00:16,760 --> 00:00:19,820 As you can see here, we get a zero division error 7 00:00:19,820 --> 00:00:22,920 indicating that division by zero occurred. 8 00:00:22,920 --> 00:00:26,060 Now what you're looking at once here is a trace back 9 00:00:26,060 --> 00:00:30,190 and it's telling you information about not only the type 10 00:00:30,190 --> 00:00:33,140 of problem that occurred, but where it occurred 11 00:00:33,140 --> 00:00:34,250 in your code. 12 00:00:34,250 --> 00:00:38,110 The code that was executing when the exception happened 13 00:00:38,110 --> 00:00:42,060 terminates and in the context of a IPtyhon session 14 00:00:42,060 --> 00:00:45,210 like this one you simply get the next In prompt 15 00:00:45,210 --> 00:00:48,290 so that you can continue your interactive session, 16 00:00:48,290 --> 00:00:51,810 but if this were in a script, the script would presumably 17 00:00:51,810 --> 00:00:55,530 terminate at this point because we don't have any code 18 00:00:55,530 --> 00:00:59,970 that says what to do if a zero division error occurs. 19 00:00:59,970 --> 00:01:02,840 In another case that we saw previously 20 00:01:02,840 --> 00:01:06,210 where an exception occurred, for example, 21 00:01:06,210 --> 00:01:09,870 if I'm doing user input and I prompt the user to enter 22 00:01:09,870 --> 00:01:12,560 an integer and then the user types something 23 00:01:12,560 --> 00:01:16,000 and that value gets returned by the input function 24 00:01:16,000 --> 00:01:18,950 let's assume that again we wanted an integer, 25 00:01:18,950 --> 00:01:21,850 but the user types something that's not an integer 26 00:01:21,850 --> 00:01:25,250 like hello in that case we get a value error. 27 00:01:25,250 --> 00:01:27,930 And again it points out the snippet in which 28 00:01:27,930 --> 00:01:30,820 the problem occurred, gives me an error message 29 00:01:30,820 --> 00:01:33,540 with a little bit of more information as well. 30 00:01:33,540 --> 00:01:36,750 In particular the value hello could not be turned 31 00:01:36,750 --> 00:01:39,650 into an integer with base 10. 32 00:01:39,650 --> 00:01:44,350 So these are a couple of examples of basic exceptions 33 00:01:44,350 --> 00:01:47,420 that can be encountered when you're dealing 34 00:01:47,420 --> 00:01:50,450 with file processing, network connections, 35 00:01:50,450 --> 00:01:53,010 database processing, they're tend to be 36 00:01:53,010 --> 00:01:56,360 many more possibilities for exceptions to occur 37 00:01:56,360 --> 00:01:58,640 and depending on what it is you're doing 38 00:01:58,640 --> 00:02:01,920 you may or may not need more robust code 39 00:02:01,920 --> 00:02:04,630 to deal with those problems as they occur. 40 00:02:04,630 --> 00:02:07,700 If you're simply in an interactive session like this one 41 00:02:07,700 --> 00:02:10,900 you might not need to deal with a problem you may simply 42 00:02:10,900 --> 00:02:14,220 execute a new snippet, but if you're dealing with a script 43 00:02:14,220 --> 00:02:17,370 that perhaps performs a larger task you might want 44 00:02:17,370 --> 00:02:19,340 some more robust code in there. 45 00:02:19,340 --> 00:02:21,540 And that's what we're going to start looking at 46 00:02:21,540 --> 00:02:23,003 in the next example.