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 built-in exceptions, another one is the user-defined 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 built-in exceptions are listed here. So Java has some predefined exceptions
defined exceptions and all exceptions are the subclass of the exception class
So, Thrable is a class which is having the package that is Java
. . . So, Java.Lang dot Throbble. So it has got inherited to the two subclasses
So one is the errors. So it is having the class that is the Java
. . . . . . . . . . . . . . . . . exceptions, which is having the class that is a Java. length
Under this Java. .Lang. class we are having multiple different subclasses so some of them are out of memory
error stack overflow error etc and this java langdot exception is a superclass for multiple different subclasses so i exception SQL exception file not found exception class not found exception we having this Java Lankt runtime exception 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 you'll be doing some arithmetic operations
and if you find some exceptions are occurring, then this exception will be thrown
So, arithmetic errors such as divide by zero. So, array index out-of-bounds exception
From the name, it is quite obvious that I'm trying to access some subscript or the location of an array
which is beyond the definition. So index exceeds the risk. 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 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 array is my
array which is having five consecutive locations so five elements we have 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 and the
subscript will be ranging from zero to four so if any subscript if we mentioned which
is beyond this range then obviously one exception will be occurring so here
here we are printing the value of this array from the subscript number 10 which is
quite well greater than the value 4 that is a maximum subscript possible for this
array and for this situation one exception will be raised and that's why we've
written a catch block just following the tri block here and this catch block is handling array index out of bounds exception and is a respective object for that and here
we 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 outer print element statement we're 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 object obviously that will raise one exception so one
exception will be produced and that's why this particular code has been put within
the tri block and immediately this code is following the catch block and that is a
null pointed exception e so system dot outd printer length the string is pointing to
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 integer
So now integer.d. Parse, I.N, B, C string, which is not at all possible because