WEBVTT 00:00:07.180 --> 00:00:11.400 In this video we're going to learn javascript errors. 00:00:11.580 --> 00:00:16.420 OK let's run a piece of code that we know is going to give us an error. 00:00:16.860 --> 00:00:23.410 So if we use a function some that we have not defined and some of three and four. 00:00:24.040 --> 00:00:24.450 OK. 00:00:24.480 --> 00:00:28.920 And if we run that we have a look at the console. 00:00:29.100 --> 00:00:30.890 We're going to see an error message. 00:00:30.890 --> 00:00:32.460 Sum is not defined. 00:00:32.800 --> 00:00:44.040 OK so now we want to find a way of getting this error message and then using it to change the value 00:00:44.040 --> 00:00:46.820 of a of any Shamal element for example. 00:00:47.550 --> 00:00:52.790 OK so what are you going to need. 00:00:52.830 --> 00:00:56.210 We will need a try statement. 00:00:56.670 --> 00:01:06.630 So basically the Troy statements will allow us to use or to execute a piece of code and test it for 00:01:06.900 --> 00:01:07.790 errors. 00:01:08.160 --> 00:01:19.290 Ok so the syntax is Troy followed by the code to be executed in curly brackets. 00:01:19.380 --> 00:01:22.910 In our case we want to test this line of code. 00:01:22.910 --> 00:01:23.530 OK. 00:01:23.700 --> 00:01:26.860 And then we're going to need another statesman's. 00:01:26.940 --> 00:01:29.030 It's a catch statesman's. 00:01:29.400 --> 00:01:39.480 So basically if an error happens in the try block then this is going to be the code to execute. 00:01:39.540 --> 00:01:40.530 If there's an error. 00:01:40.710 --> 00:01:45.340 So the syntax is by using the keyword catch. 00:01:45.410 --> 00:01:46.230 OK. 00:01:46.400 --> 00:01:51.980 And then between parentheses we need to put the variable air e r r. 00:01:52.340 --> 00:01:53.310 OK. 00:01:53.990 --> 00:02:02.600 And then follows the piece of code to be executed if there is an error. 00:02:02.670 --> 00:02:08.520 So what we would like to do here is to display the error message inside a paragraph. 00:02:08.520 --> 00:02:09.930 So let's create a paragraph 00:02:18.280 --> 00:02:23.880 OK and give us an ID of error. 00:02:23.880 --> 00:02:29.240 Also we want to style this paragraph. 00:02:31.260 --> 00:02:44.550 So when you leave a space changed color to something red it is. 00:02:44.550 --> 00:02:46.580 It's this color for example. 00:02:47.140 --> 00:02:48.120 OK. 00:02:48.250 --> 00:02:51.030 And the code to be executed if there is an error. 00:02:51.030 --> 00:02:59.790 So we want to change the contents of the paragraphs so the documents gets elements by id error and we 00:02:59.790 --> 00:03:05.490 want to change the a shemale to the error message. 00:03:05.550 --> 00:03:12.810 So this variable is an objects and one of its properties is message which is the message is displayed 00:03:12.810 --> 00:03:13.740 here. 00:03:13.740 --> 00:03:20.040 OK so we need to set the Ishmail to air Dot's message. 00:03:20.520 --> 00:03:21.150 OK. 00:03:21.150 --> 00:03:29.940 So let's try it now and we can see that the sum is not defined in the paragraph