Introduction to Exception Handling in Java
Exception is an abnormal condition that arises in the program during execution. When such a condition arises in the program, an appropriate code is written so that it can be handled. It is very much similar to the error codes returned by a subroutine in the C language. Whatever value the function returns can be checked, and depending upon the value you can make out whether it is executed successfully or were there any errors. If there is an error then you need to match the error code with the error list and find out what error occurred. Java runtime environment has adopted this feature extensively using object-oriented methodology in the form of exception handling.
By using the exception handling you can prevent your program from abruptly ending, flashing surprising and annoying error messages. On the contrary, if a minor error crops up it can be handled during runtime and your program resumes from there on without crashing down.
All exceptions in Java are subclasses of the built-in-class called Throwable. There are two main subclasses under throwable: Exception and Error.
The Exception class caters to all the problems that should be caught by the user program. Runtime Exception is an important sub class of Exception; exception of these kinds are predefined such as divided by zero etc. the exception that are not expected to be caught by user program and more or less fatal in nature come under the Error subclass, for example stack overflow. These are the catastrophic conditions, which are dealt by the run time environment itself. Apart from the system-generated exception, the user also can explicitly define their own exceptions.
|All times are GMT +5.5. The time now is 01:29.|