Why we have Runtime Exceptioons in Java
Oracle defines Exception as
"An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions."
We have three categories of exception as:-
Checked Exceptions , which are subject to catch . All exceptions are checked exceptions, except for those indicated by
Runtime Exceptions are internal to the application and system does not expect to recover from. NullPointerException is type of RunTime Exception
Error are exceptions which are external to applications like OutOfMemory Exception, StackOverFlow Exception.
The class diagram of Exception is as follows:-
This discussion is regarding why we have Runtime type of exceptions in Java.
When exception was first designed, there was worry about conditions that occur because of
Generally, it would not be the method that throw such an exception, it would be the underlying VM. It would just make the code longer and less robust To clear this , a special sort of exception, called RunTime Exception was build into the Java. Since RunTimeException can be thrown any time and need not to be declared as part of method signature.
Use: Sometime in the midst of writing the implementation programmer discovers that there is an exception condition that hadn't thought in the original design. One way , is to declare the exception as Exception as subclass of Runtime Exception. That way, one need not to change the calling code.
But , it will result more work and headache in future, when you try to find out why system is failing, Since it not mandate to catch.....
"An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions."
We have three categories of exception as:-
Checked Exceptions , which are subject to catch . All exceptions are checked exceptions, except for those indicated by
Error
, RuntimeException
, and their subclassesRuntime Exceptions are internal to the application and system does not expect to recover from. NullPointerException is type of RunTime Exception
Error are exceptions which are external to applications like OutOfMemory Exception, StackOverFlow Exception.
The class diagram of Exception is as follows:-
This discussion is regarding why we have Runtime type of exceptions in Java.
When exception was first designed, there was worry about conditions that occur because of
- problems with the machine on which the program being run
- bugs in VM
- security violations.
Generally, it would not be the method that throw such an exception, it would be the underlying VM. It would just make the code longer and less robust To clear this , a special sort of exception, called RunTime Exception was build into the Java. Since RunTimeException can be thrown any time and need not to be declared as part of method signature.
Use: Sometime in the midst of writing the implementation programmer discovers that there is an exception condition that hadn't thought in the original design. One way , is to declare the exception as Exception as subclass of Runtime Exception. That way, one need not to change the calling code.
But , it will result more work and headache in future, when you try to find out why system is failing, Since it not mandate to catch.....
Comments
Post a Comment