1
00:00:06,090 --> 00:00:07,440
In this section.

2
00:00:07,440 --> 00:00:11,430
Let's talk about how we can handle errors.

3
00:00:11,460 --> 00:00:19,860
In that way, we can send user friendly errors to the end user, or we will know the type of errors

4
00:00:19,860 --> 00:00:22,890
that might occur in our application.

5
00:00:22,890 --> 00:00:27,780
So let's answer to the question what is error handling?

6
00:00:27,810 --> 00:00:29,790
Here we go.

7
00:00:30,000 --> 00:00:40,020
It is a process of dealing with errors that occur during the execution of a program, or it is a way

8
00:00:40,020 --> 00:00:46,410
of preventing the program from crashing and allowing it to continue running smoothly.

9
00:00:46,440 --> 00:00:49,760
So that is what we call error handling.

10
00:00:49,770 --> 00:00:56,550
Before we can handle errors, we need to know the types of errors that might occur.

11
00:00:56,820 --> 00:00:59,910
And I have categorized them into two.

12
00:00:59,940 --> 00:01:04,530
The first one is what we call operational errors.

13
00:01:04,530 --> 00:01:07,410
So what is operational error?

14
00:01:07,530 --> 00:01:16,650
Well, operational errors are unexpected errors that occur when the express server is unable to start

15
00:01:16,650 --> 00:01:18,720
or shut down gracefully.

16
00:01:18,960 --> 00:01:26,250
So this has nothing to do with our code that we write or it is not due to our programming mistake.

17
00:01:26,490 --> 00:01:33,940
So operational errors are usually fatal and we prevent the express server from starting up.

18
00:01:33,960 --> 00:01:37,820
So this is what we call operational errors.

19
00:01:37,830 --> 00:01:43,170
The next type of error is what we call programming errors.

20
00:01:43,200 --> 00:01:48,120
Programming errors are caused by bugs in our code.

21
00:01:48,270 --> 00:01:56,760
They are not due to incorrect inputs or network issue or database and many more, but instead programming

22
00:01:56,760 --> 00:02:03,140
errors that can cause the program to crash, freeze or produce incorrect results.

23
00:02:03,150 --> 00:02:06,570
And this is what we call the programming errors.

24
00:02:06,570 --> 00:02:10,320
And these kind of errors are caused by the developers.

25
00:02:10,620 --> 00:02:12,870
Is something with the code that we write.

26
00:02:12,990 --> 00:02:16,200
So let's have a look at example of errors.

27
00:02:16,200 --> 00:02:23,420
And the each category is the first one and the operational error is what we call port conflict.

28
00:02:23,430 --> 00:02:30,780
When we say port conflict, it means that using one port for two or more applications, let's say that

29
00:02:30,780 --> 00:02:39,030
you are running React application and for React it is uses a port called 3000 and when developing your

30
00:02:39,030 --> 00:02:44,730
server or your back end, you are also using 3000 for the back end.

31
00:02:44,760 --> 00:02:51,960
If you use the same port, you're going to see a message that port is already in use and this kind of

32
00:02:51,960 --> 00:02:57,060
error is not due to us, but instead it is operational errors.

33
00:02:57,090 --> 00:03:01,880
The next one is what we call network issues, as the name implies.

34
00:03:02,040 --> 00:03:10,920
Next one is failed to connect to database and this one can due to network issue or invalid validation.

35
00:03:11,100 --> 00:03:18,870
The next type is what we call invalid path access, and the next one is database validation error.

36
00:03:18,960 --> 00:03:22,260
The next is unable to connect to the server.

37
00:03:22,260 --> 00:03:25,050
And lastly, request timeout.

38
00:03:25,050 --> 00:03:30,840
We have many of them, but these are examples of operational errors.

39
00:03:30,840 --> 00:03:33,150
So what about programming errors?

40
00:03:33,180 --> 00:03:41,520
Well, one example is attempting to use an undeclared variable, and sometimes it happens often.

41
00:03:41,640 --> 00:03:48,480
And then the next point is that forgetting to include a required file or module.

42
00:03:48,630 --> 00:03:54,520
The next point is passing the wrong data type to a function or a method.

43
00:03:54,540 --> 00:04:03,000
Let's say that we have created a function that takes in an array as an argument, but instead upon calling,

44
00:04:03,000 --> 00:04:05,010
we are passing in a boolean.

45
00:04:05,010 --> 00:04:09,030
In that way we are going to see on expected results.

46
00:04:09,030 --> 00:04:16,440
The next type of error is what we call performing an operation on incompatible data types.

47
00:04:16,440 --> 00:04:19,620
For example, you are adding boolean to an array.

48
00:04:19,649 --> 00:04:21,060
It's incompatible, right?

49
00:04:21,060 --> 00:04:24,100
So this kind of error is due to us.

50
00:04:24,120 --> 00:04:32,970
The next one is using an incorrect operator such as equal to instead of double equal to or triple equal

51
00:04:32,970 --> 00:04:39,690
to the next type is called forgetting to close a block of code with carry brackets.

52
00:04:39,690 --> 00:04:42,870
And these are all types of programming errors.

53
00:04:42,870 --> 00:04:47,850
And lastly, accidentally create an infinite loop.

54
00:04:47,850 --> 00:04:51,060
So these are types of errors that might.

55
00:04:51,060 --> 00:04:58,890
Okay, now that we know the overview or the types of errors in this video, let's see how we can handle

56
00:04:58,890 --> 00:05:02,940
errors in our express application step by step.

