WEBVTT

00:00.120 --> 00:02.429
in this video we are going to discuss

00:02.429 --> 00:04.048
built-in exceptions

00:04.049 --> 00:06.600
we know that exceptions in Java can be

00:06.600 --> 00:08.820
divided into two categories one is the

00:08.820 --> 00:10.860
building exceptions and other one is

00:10.860 --> 00:13.049
that user different exceptions so in

00:13.049 --> 00:15.120
this case we are concentrating only on

00:15.120 --> 00:17.670
the built in exceptions that is some

00:17.670 --> 00:19.740
exceptions which are predefined within

00:19.740 --> 00:22.140
this Java language can be used in our

00:22.140 --> 00:26.160
coding so some building exceptions are

00:26.160 --> 00:29.279
listed here so Java has some predefined

00:29.279 --> 00:31.679
exceptions and all exceptions are the

00:31.679 --> 00:34.910
subclass of the exception class so

00:34.910 --> 00:37.590
throwable is a class which is having the

00:37.590 --> 00:40.110
package that is Java dot Lang so Java

00:40.110 --> 00:42.390
dot length dot Tribble so it has got

00:42.390 --> 00:46.289
inherited to the two subclasses so one

00:46.289 --> 00:48.719
is the errors so it is having the class

00:48.719 --> 00:50.820
that is the Java dot length dot error in

00:50.820 --> 00:53.039
other words the exceptions so which is

00:53.039 --> 00:54.660
having the class that is a Java dot

00:54.660 --> 00:57.899
length dot exception under this Java dot

00:57.899 --> 00:59.699
length of error class were having

00:59.699 --> 01:02.370
multiple different subclasses so some of

01:02.370 --> 01:04.978
them are out of memory errors stack

01:04.979 --> 01:08.700
overflow error etc and this Java dot

01:08.700 --> 01:11.369
length dot exception is a superclass for

01:11.369 --> 01:13.290
multiple different subclasses

01:13.290 --> 01:16.229
so I exception SQL exception file not

01:16.229 --> 01:18.450
found exception class not found

01:18.450 --> 01:20.880
exception etcetera we're having this

01:20.880 --> 01:24.030
Java dot length at runtime exception who

01:24.030 --> 01:25.320
just have which is having some

01:25.320 --> 01:26.460
subclasses here

01:26.460 --> 01:28.560
arithmetic exception null pointer

01:28.560 --> 01:31.189
exception index out of bounds exception

01:31.189 --> 01:34.770
illegal argument exception and etc so

01:34.770 --> 01:36.780
this is a hierarchical diagram partial

01:36.780 --> 01:40.619
we have shown here now let us go for

01:40.619 --> 01:43.649
some built-in exceptions so arithmetic

01:43.649 --> 01:45.720
exception from the name it is quite

01:45.720 --> 01:47.220
obvious that when we'll be doing some

01:47.220 --> 01:48.930
arithmetic operations and if we find

01:48.930 --> 01:51.030
some exceptions are occurring then this

01:51.030 --> 01:53.610
exception will be thrown so arithmetic

01:53.610 --> 01:56.219
errors such as divide two by zero so

01:56.219 --> 02:00.030
array index out of bounds exception from

02:00.030 --> 02:01.920
the name it is quite obvious that I am

02:01.920 --> 02:04.890
trying to access some subscript or the

02:04.890 --> 02:07.469
location of an array which is beyond the

02:07.469 --> 02:10.440
definition so index exceeds the range of

02:10.440 --> 02:13.080
the array so in those cases this

02:13.080 --> 02:16.080
array index out of bounds exception will

02:16.080 --> 02:20.040
be thrown null pointer exception invalid

02:20.040 --> 02:23.760
use of null reference number format

02:23.760 --> 02:26.730
exception invalid conversion of a string

02:26.730 --> 02:29.700
to a numeric format so in those cases

02:29.700 --> 02:32.220
this number format exception may be

02:32.220 --> 02:35.610
thrown no such method exception we are

02:35.610 --> 02:37.620
going for another type of no such method

02:37.620 --> 02:40.830
exception a requested method does not

02:40.830 --> 02:43.470
exist so in this we are having different

02:43.470 --> 02:44.940
exceptions we are having the different

02:44.940 --> 02:47.280
descriptions so for the better and

02:47.280 --> 02:48.600
understanding let us go for one

02:48.600 --> 02:50.880
practical demonstration for the ease of

02:50.880 --> 02:55.170
your knowledge generation here in this

02:55.170 --> 02:57.900
Java program I have defined one integer

02:57.900 --> 03:00.060
array the name of the air is my array

03:00.060 --> 03:02.100
which is having five consecutive

03:02.100 --> 03:05.400
locations so five elements were put into

03:05.400 --> 03:07.500
this array and during initialization of

03:07.500 --> 03:10.170
this array we have also mentioned the

03:10.170 --> 03:11.640
size of the array that means it is

03:11.640 --> 03:14.280
having five consecutive locations as a

03:14.280 --> 03:16.800
subscript will be ranging from zero to

03:16.800 --> 03:19.650
four so if any subscript if we mention

03:19.650 --> 03:21.690
which is beyond this range then

03:21.690 --> 03:23.519
obviously one exception will be

03:23.519 --> 03:25.739
occurring so here you are printing the

03:25.739 --> 03:28.260
value of this array from the subscript

03:28.260 --> 03:31.019
number ten which is quite well a greater

03:31.019 --> 03:33.060
than the value for that is a maximum

03:33.060 --> 03:35.160
subscript possible for this array and

03:35.160 --> 03:38.280
for this situation one exception will be

03:38.280 --> 03:40.140
raised and that's why we have written

03:40.140 --> 03:42.330
our catch block just following the try

03:42.330 --> 03:44.430
block here and this cache block is

03:44.430 --> 03:46.830
handling array index out of bounds

03:46.830 --> 03:50.190
exception and is a respective object for

03:50.190 --> 03:51.959
that and here you are having the

03:51.959 --> 03:53.670
remedial actions that means we are

03:53.670 --> 03:56.250
printing one statement that is invalid

03:56.250 --> 03:59.880
index of the array okay now next time we

03:59.880 --> 04:03.030
will define one string object string

04:03.030 --> 04:04.560
class object that is a my string

04:04.560 --> 04:07.410
initialized with null and here in this

04:07.410 --> 04:09.540
particular system dot out dot println

04:09.540 --> 04:11.610
statement we are trying to print the

04:11.610 --> 04:14.100
character at the fifth location but this

04:14.100 --> 04:16.049
my string has got initialized with null

04:16.049 --> 04:18.390
so if I want to pick up the character

04:18.390 --> 04:20.700
from the fifth index of this particular

04:20.700 --> 04:23.610
my string string object obviously that

04:23.610 --> 04:25.410
will raise one exception

04:25.410 --> 04:26.880
so one exception

04:26.880 --> 04:28.650
produced and that's why this particular

04:28.650 --> 04:30.780
cord has been put within the cry block

04:30.780 --> 04:32.940
and immediately this code is following

04:32.940 --> 04:34.770
the catch block and that is a null

04:34.770 --> 04:37.890
pointer exception e so system dot out

04:37.890 --> 04:40.380
dot println the string is pointing to a

04:40.380 --> 04:42.570
null value so respective string

04:42.570 --> 04:44.340
respective message will get printed

04:44.340 --> 04:47.790
which is the error handling part okay

04:47.790 --> 04:50.340
now see here we are trying to convert

04:50.340 --> 04:53.340
this ABC this particular string as an

04:53.340 --> 04:54.330
indigent

04:54.330 --> 04:57.870
so now integer dot parts int ABC string

04:57.870 --> 05:00.390
which is not at all possible because ABC

05:00.390 --> 05:02.670
cannot be converted to a number so

05:02.670 --> 05:05.280
that's why int number well we are when

05:05.280 --> 05:07.410
trying to initialize this number that is

05:07.410 --> 05:09.810
a int variable it is not possible and

05:09.810 --> 05:11.430
that will raise one exception and that

05:11.430 --> 05:13.740
exception is known as the number format

05:13.740 --> 05:15.870
exception so what will happen this

05:15.870 --> 05:17.640
particular line will remain unreachable

05:17.640 --> 05:20.370
and executed whenever we were trying to

05:20.370 --> 05:23.040
do this I India dot parse int we're

05:23.040 --> 05:24.240
calling this particular method

05:24.240 --> 05:26.790
converting one string to number then

05:26.790 --> 05:28.890
immediately exception will be raised and

05:28.890 --> 05:30.900
the catch block will get the control

05:30.900 --> 05:33.000
here and here to here the exception name

05:33.000 --> 05:35.580
is number format exception and this

05:35.580 --> 05:38.430
remedial statement will be printed so

05:38.430 --> 05:40.650
now let us go for the execution you can

05:40.650 --> 05:42.780
find that whenever I am executing

05:42.780 --> 05:45.900
inverted index of the array that means

05:45.900 --> 05:47.640
this line has got executed that means

05:47.640 --> 05:50.760
the control came to this in array index

05:50.760 --> 05:53.310
out of bounds exception cache block the

05:53.310 --> 05:55.590
string is pointing a null value that

05:55.590 --> 05:57.660
means this line has got printed that

05:57.660 --> 05:59.070
means the control came to the cache

05:59.070 --> 06:01.740
block for this null pointer exception II

06:01.740 --> 06:04.440
and it is not a valid number that means

06:04.440 --> 06:07.050
control came to this catch block here so

06:07.050 --> 06:09.360
in this way you can find that how this

06:09.360 --> 06:11.760
inbuilt exceptions in Java we have

06:11.760 --> 06:15.150
handled so now if I put this one as 1 so

06:15.150 --> 06:17.490
0 to 4 is a valid index here because

06:17.490 --> 06:19.800
we're having 5 integers are there so

06:19.800 --> 06:22.080
that's why one index is valid so if I

06:22.080 --> 06:24.780
put here say 0 let us see that what will

06:24.780 --> 06:27.060
happen then obviously some exception

06:27.060 --> 06:28.980
will be there and here if we put here

06:28.980 --> 06:31.800
100 then 100 which is a string can

06:31.800 --> 06:34.020
easily be converted to a number so now

06:34.020 --> 06:37.140
see what will happen so the value of the

06:37.140 --> 06:40.050
of my array 10 so here it should write

06:40.050 --> 06:41.230
this one as

06:41.230 --> 06:43.570
I'm writing this one as one so now if I

06:43.570 --> 06:46.389
go for this so the value of my edit one

06:46.389 --> 06:49.360
is 20s at the index number zero index

06:49.360 --> 06:51.550
number one is containing twenty the

06:51.550 --> 06:53.500
string is pointing a null value that

06:53.500 --> 06:56.139
means here it is producing exceptions

06:56.139 --> 06:58.180
because the string has got initialized

06:58.180 --> 07:00.669
with a null but let us suppose I am just

07:00.669 --> 07:04.060
putting this one as ABCD so now see what

07:04.060 --> 07:08.680
will happen so it is it is picking up

07:08.680 --> 07:10.330
the respective character zero because

07:10.330 --> 07:12.490
I'm picking up the Spree character from

07:12.490 --> 07:15.040
the zero play so a will be picked up and

07:15.040 --> 07:17.200
accordingly outputs are coming and in

07:17.200 --> 07:19.600
the last case the number is 100 that

07:19.600 --> 07:21.280
means this line caught the control so

07:21.280 --> 07:23.020
cache block is not getting the control

07:23.020 --> 07:25.030
so in this way you have explained how

07:25.030 --> 07:27.280
this inbuilt exceptions can be handled

07:27.280 --> 07:29.800
in our Java code thanks for watching

07:29.800 --> 07:32.069
this video
