in this video we are going to discuss
built-in exceptions
we know that exceptions in Java can be
divided into two categories one is the
building exceptions and other one is
that user different exceptions so in
this case we are concentrating only on
the built in exceptions that is some
exceptions which are predefined within
this Java language can be used in our
coding so some building exceptions are
listed here so Java has some predefined
exceptions and all exceptions are the
subclass of the exception class so
throwable is a class which is having the
package that is Java dot Lang so Java
dot length dot Tribble so it has got
inherited to the two subclasses so one
is the errors so it is having the class
that is the Java dot length dot error in
other words the exceptions so which is
having the class that is a Java dot
length dot exception under this Java dot
length of error class were having
multiple different subclasses so some of
them are out of memory errors stack
overflow error etc and this Java dot
length dot exception is a superclass for
multiple different subclasses
so I exception SQL exception file not
found exception class not found
exception etcetera we're having this
Java dot length at runtime exception who
just have which is having some
subclasses here
arithmetic exception null pointer
exception index out of bounds exception
illegal argument exception and etc so
this is a hierarchical diagram partial
we have shown here now let us go for
some built-in exceptions so arithmetic
exception from the name it is quite
obvious that when we'll be doing some
arithmetic operations and if we find
some exceptions are occurring then this
exception will be thrown so arithmetic
errors such as divide two by zero so
array index out of bounds exception from
the name it is quite obvious that I am
trying to access some subscript or the
location of an array which is beyond the
definition so index exceeds the range of
the array so in those cases this
array index out of bounds exception will
be thrown null pointer exception invalid
use of null reference number format
exception invalid conversion of a string
to a numeric format so in those cases
this number format exception may be
thrown no such method exception we are
going for another type of no such method
exception a requested method does not
exist so in this we are having different
exceptions we are having the different
descriptions so for the better and
understanding let us go for one
practical demonstration for the ease of
your knowledge generation here in this
Java program I have defined one integer
array the name of the air is my array
which is having five consecutive
locations so five elements were put into
this array and during initialization of
this array we have also mentioned the
size of the array that means it is
having five consecutive locations as a
subscript will be ranging from zero to
four so if any subscript if we mention
which is beyond this range then
obviously one exception will be
occurring so here you are printing the
value of this array from the subscript
number ten which is quite well a greater
than the value for that is a maximum
subscript possible for this array and
for this situation one exception will be
raised and that's why we have written
our catch block just following the try
block here and this cache block is
handling array index out of bounds
exception and is a respective object for
that and here you are having the
remedial actions that means we are
printing one statement that is invalid
index of the array okay now next time we
will define one string object string
class object that is a my string
initialized with null and here in this
particular system dot out dot println
statement we are trying to print the
character at the fifth location but this
my string has got initialized with null
so if I want to pick up the character
from the fifth index of this particular
my string string object obviously that
will raise one exception
so one exception
produced and that's why this particular
cord has been put within the cry block
and immediately this code is following
the catch block and that is a null
pointer exception e so system dot out
dot println the string is pointing to a
null value so respective string
respective message will get printed
which is the error handling part okay
now see here we are trying to convert
this ABC this particular string as an
indigent
so now integer dot parts int ABC string
which is not at all possible because ABC
cannot be converted to a number so
that's why int number well we are when
trying to initialize this number that is
a int variable it is not possible and
that will raise one exception and that
exception is known as the number format
exception so what will happen this
particular line will remain unreachable
and executed whenever we were trying to
do this I India dot parse int we're
calling this particular method
converting one string to number then
immediately exception will be raised and
the catch block will get the control
here and here to here the exception name
is number format exception and this
remedial statement will be printed so
now let us go for the execution you can
find that whenever I am executing
inverted index of the array that means
this line has got executed that means
the control came to this in array index
out of bounds exception cache block the
string is pointing a null value that
means this line has got printed that
means the control came to the cache
block for this null pointer exception II
and it is not a valid number that means
control came to this catch block here so
in this way you can find that how this
inbuilt exceptions in Java we have
handled so now if I put this one as 1 so
0 to 4 is a valid index here because
we're having 5 integers are there so
that's why one index is valid so if I
put here say 0 let us see that what will
happen then obviously some exception
will be there and here if we put here
100 then 100 which is a string can
easily be converted to a number so now
see what will happen so the value of the
of my array 10 so here it should write
this one as
I'm writing this one as one so now if I
go for this so the value of my edit one
is 20s at the index number zero index
number one is containing twenty the
string is pointing a null value that
means here it is producing exceptions
because the string has got initialized
with a null but let us suppose I am just
putting this one as ABCD so now see what
will happen so it is it is picking up
the respective character zero because
I'm picking up the Spree character from
the zero play so a will be picked up and
accordingly outputs are coming and in
the last case the number is 100 that
means this line caught the control so
cache block is not getting the control
so in this way you have explained how
this inbuilt exceptions can be handled
in our Java code thanks for watching
this video