1
00:00:00,360 --> 00:00:05,820
You already know that when you try to do something that doesn't make sense, for example, trying to

2
00:00:05,820 --> 00:00:09,630
add 12.3 to the string high, you get an error.

3
00:00:09,630 --> 00:00:10,760
So that is the error.

4
00:00:10,770 --> 00:00:16,890
But what you probably don't know yet is that there are two major types of errors in Python.

5
00:00:16,890 --> 00:00:19,830
You have syntax errors and then you have exceptions.

6
00:00:19,830 --> 00:00:23,400
So we have been referring to these as just errors.

7
00:00:23,610 --> 00:00:30,360
But in this code experiment, video today will explain you the distinction so that you can distinguish

8
00:00:30,360 --> 00:00:33,570
what syntax errors are and what exceptions are.

9
00:00:33,600 --> 00:00:37,950
So for that, we're going to be working on our app.

10
00:00:37,950 --> 00:00:40,890
And here is what I would like you to try for.

11
00:00:42,600 --> 00:00:43,200
Now.

12
00:00:43,200 --> 00:00:48,120
So please go under live where the complete condition is.

13
00:00:48,120 --> 00:00:55,260
So where we check if the user command starts with complete and then we have this try block where we

14
00:00:55,260 --> 00:00:58,830
try to get the number after the complete command.

15
00:00:58,830 --> 00:01:05,580
So if the user enters complete three, then we get the part of the index nine, which should give us

16
00:01:05,580 --> 00:01:09,090
the number and then we have the file operation here.

17
00:01:09,240 --> 00:01:15,990
Then we remove the to do with that number from the list and we write it to do in the list.

18
00:01:15,990 --> 00:01:20,610
Now what happens if we remove these brackets here?

19
00:01:20,610 --> 00:01:23,180
So try to think what will happen.

20
00:01:23,370 --> 00:01:27,090
We do have this try and accept block Right.

21
00:01:27,090 --> 00:01:31,770
So that means the interpreter should try to execute this block.

22
00:01:31,770 --> 00:01:38,910
If it finds an error in that block of code, then it should execute these lines under except that's

23
00:01:38,910 --> 00:01:40,950
how try and accept works.

24
00:01:40,950 --> 00:01:42,600
But is that true?

25
00:01:42,600 --> 00:01:45,030
So are we going to get this printed out?

26
00:01:45,030 --> 00:01:48,450
So let's try run and this is what we get.

27
00:01:48,450 --> 00:01:53,280
Syntax error closing in parentheses does not match opening parentheses.

28
00:01:53,280 --> 00:01:59,340
So why didn't the try accept block handle the error?

29
00:01:59,340 --> 00:02:04,920
Why do we get a python error here when we were expecting this to be executed?

30
00:02:04,920 --> 00:02:13,920
Well, the reason is that this here is a syntax error and the try accept block only catches exceptions.

31
00:02:13,920 --> 00:02:17,160
What is the difference between a syntax error and an exception?

32
00:02:17,160 --> 00:02:23,070
Well, let's suppose that you are sending an email to someone and on your browser you have a grammar

33
00:02:23,070 --> 00:02:23,730
checker.

34
00:02:23,730 --> 00:02:27,570
So that's Checker is checking for grammar errors.

35
00:02:27,570 --> 00:02:34,470
Maybe you forgot a period or you typed in a word incorrectly so that grammar checker will check for

36
00:02:34,470 --> 00:02:35,550
syntax errors.

37
00:02:35,550 --> 00:02:40,740
So when the grammar checker tells you that oh, everything is okay, then you send all the email to

38
00:02:40,740 --> 00:02:41,670
a person.

39
00:02:41,670 --> 00:02:49,500
But then the fact that the syntax is correct doesn't mean your email content doesn't have issues.

40
00:02:49,500 --> 00:02:55,740
So the grammar checker is only able to check for syntax errors, but then the person on the other side

41
00:02:55,740 --> 00:02:57,780
they can check for logical errors.

42
00:02:57,780 --> 00:03:03,060
So maybe you said that oh, there is a file in the attachment, but you forgot to attach a file in that

43
00:03:03,060 --> 00:03:03,570
email.

44
00:03:03,570 --> 00:03:08,940
So that would be some sort of logical errors which the grammar checker cannot check.

45
00:03:08,940 --> 00:03:14,730
Similarly with the Python interpreter, there are two instances of that interpreter program.

46
00:03:14,730 --> 00:03:18,780
So first the interpreter checks your code for syntax errors.

47
00:03:19,530 --> 00:03:22,920
It doesn't go into the logic of the code itself.

48
00:03:22,920 --> 00:03:26,700
It doesn't check conditions, it doesn't check try accept blocks.

49
00:03:26,700 --> 00:03:30,040
So it just looks at the syntax model.

50
00:03:30,060 --> 00:03:35,760
IDs also have utilities integrated, which also are able to check for syntax errors.

51
00:03:35,760 --> 00:03:41,940
So all these other lines that you see are suggestions by the OR IDE.

52
00:03:41,970 --> 00:03:48,150
And then when you run the codes you get the actual source of the error, which in our case points to

53
00:03:48,150 --> 00:03:49,320
line 46.

54
00:03:49,320 --> 00:03:53,010
So that's one in there where we have a missing square bracket.

55
00:03:53,020 --> 00:03:54,270
So that is a syntax error.

56
00:03:54,300 --> 00:04:01,260
Now sometimes you'll also see that syntax errors are referred by people as just errors, and logical

57
00:04:01,260 --> 00:04:04,290
errors are referred to as exceptions.

58
00:04:04,290 --> 00:04:13,320
So a logical error, for example, would be something like if we try to remove an item using an index

59
00:04:13,320 --> 00:04:15,000
which does not exist in the list.

60
00:04:15,000 --> 00:04:20,940
So for example, if the list has five items but we try to remove eight here, so the item with index

61
00:04:20,940 --> 00:04:23,730
eight, then we would get an exception.

62
00:04:23,880 --> 00:04:32,820
So in other words, if I open the python console in here, so if we have a list and we have A and B

63
00:04:32,820 --> 00:04:41,520
as items than a dot pop and you say remove item with index five, that is not a syntax error.

64
00:04:41,520 --> 00:04:48,780
So this is an exception, although you will see people, almost anyone will just say, Oh, we got an

65
00:04:48,780 --> 00:04:49,170
error.

66
00:04:49,170 --> 00:04:54,330
So they refer to errors in general to syntax errors and exceptions as well.

67
00:04:54,570 --> 00:05:01,650
So from a practical point of view, the difference between syntax errors and exceptions doesn't matter

68
00:05:01,650 --> 00:05:05,400
as much as it matters from the theoretical point of view.

69
00:05:05,400 --> 00:05:13,080
So you should be aware that these differences exist this way you have a better understanding of how

70
00:05:13,080 --> 00:05:14,490
your programs work.

71
00:05:14,490 --> 00:05:18,390
It is beneficial in certain cases, such as in here.

72
00:05:18,570 --> 00:05:20,610
When you use this try except block.

73
00:05:20,670 --> 00:05:28,140
Now you understand that a syntax error is not code from this block because of the way the interpreter

74
00:05:28,140 --> 00:05:28,680
works.

75
00:05:28,680 --> 00:05:35,400
So it has this grammar checker component which checks the syntax first, and then it has the actual

76
00:05:35,400 --> 00:05:41,820
interpreter which interprets what you were trying to say through the correct syntax.

77
00:05:42,070 --> 00:05:48,520
Once the syntax is correct, the grammar checker gives the green light, then the interpreter component,

78
00:05:48,520 --> 00:05:55,360
which understands the language, goes on and translates the instructions into machine language.

79
00:05:55,540 --> 00:06:01,630
Then your processor processes the information and it gives the output on your computer screen.

80
00:06:02,480 --> 00:06:05,900
And so that was the experiment I wanted to try for today.

81
00:06:06,320 --> 00:06:07,850
And I'll talk to you in the next videos.

82
00:06:07,880 --> 00:06:08,300
See you.

