Transcript for:
Understanding Java Exception Hierarchy

now as we have seen exception is a superclass right and in that we have a lot of subclasses now let's try to understand the entire hierarchy in fact we'll not talk about all the classes let's try to give you the general idea and with this idea we'll understand okay what class belongs where and which exceptions are compensory to handle and which are not okay that's important point to remember so on top we have the object class now why it's on top because every class in Java extends object even if you don't mention it's there right so give let's give the respect to object class now below that we have one class called throwable now if you remember while searching for the class uh we have seen exception class extends variable so that's on top one more trivia here most of the names which ends with able are actually interfaces okay runnable civilizable cloneable but coming to exception thrabel is also able at the end but it's a class okay that's the only exception which I have seen till now now below this we have two and okay that sounds weird because we have only seen exception right so we have except here and apart from this we have one more which is called error okay now why we have not talked about error yet we are only talking about exception the thing is when we talked about runtime exception we have mentioned that it is something you can handle okay so exceptions are something which you can and you should handle others you can't okay when the others hit it will simply stop the execution normally it doesn't happen but if it happens you can't do anything with that example of this it can be the thread that what if your thread dies example of this can be i o error something goes wrong with the input output we have few more which is your virtual machine error it can be one of the example I can give you here is what if you have out of memory so what if your memory is not there so what how can you handle that okay so this type of adults you can't actually handle so this is something it's there it will not happen but we cannot handle that even if it happens what you can handle is exception now in exception as well we have multiple options here so we we have the first one which is runtime exception so we have the subclass of exception is one time exception and on the other hand we have a lot of different exceptions here example of this could be a skill exception example of this could be i o exception and many more but we are just trying to understand the simple one so we have these two uh we have many more as I mentioned now in runtime exception also we have a lot of different exceptions here we have seen most of it in fact we have seen uh arithmetic exception uh then we have add a index out of bounds exception and then we have null Point exception now all this comes on the runtime exception this is an null Point exception now the thing is why you have to remember this thing not everything you have to remember but few of them see all these runtime exceptions are actually called unchecked exceptions and all the other here on on this side they are called checked exception now why they are unchecked and checked most of the time when you write the line your compiler will not force you to handle the exception okay it will say hey it's your choice to handle the exception so all the runtime exception all this all the classes here it's your choice if you want to handle them or not but whenever your compiler sees that there is a line which can raise a exception which is not runtime exception example it can raise uh SQL exception IO exception in that case it will ask you compulsory to handle the exception if you remember when we were trying to load the class with the help of class dot for name on the right side of the method we have mentioned it throws the io exception right so it was forcing you to handle it okay okay we have not talked about those yet but we'll talk about it so basically uh these are all checked and this are all unchecked here and there is something you should not be worrying about it will not happen most of the time and this is something you have to handle by yourself so I hope this diagram makes some sense this is the top class which is there in every Java code and this is the authorable which is a parent class of exception and error in exception we have lot of different exceptions if you get SQL exception in your code you have to handle it compulsory I have exception compulsion apart from this if you have a runtime exception it's your choice to enter it or not but as a good programmer if you want to keep your client happy please handle the exceptions