Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
praveen kumaar wrote:Hi Kiran!
As you know checked exceptions are one which can be caught during compiling your code and can be handled at the compiler level.but in case of unchecked exception compiler don't checks it when it compiles your code means you can leave it.
Handling a Exceptions means you know about how and when that exceptional situation may arise so you handle them.
now for ex:-RuntimeException do you really think you can handle them it means you know about the situation when it arises so why don't you remove that error
instead of handling it.one can not predict when this exception may arise because their are not predictable(may arise due to several reasons like outofmemory,illegalstate...etc).
Hope This will help!
kind Regards!
praveen.
praveen kumaar wrote:
As you know checked exceptions are one which can be caught during compiling your code and can be handled at the compiler level.but in case of unchecked exception compiler don't checks it when it compiles your code means you can leave it.
Junilu Lacar wrote:
praveen kumaar wrote:
As you know checked exceptions are one which can be caught during compiling your code and can be handled at the compiler level.but in case of unchecked exception compiler don't checks it when it compiles your code means you can leave it.
As worded, this is incorrect. Exceptions, both checked and unchecked, can only be caught at runtime because that's the only time they will ever get thrown. Program code is never executed when it is compiled. However, code can be analyzed at compile time and the compiler can check it for compliance with the rule that code from which a checked exception can be thrown must either handle the exception with a catch block or declare the exception in a throws clause in that code's method header. That rule does not apply to code that can throw an unchecked exception.
Many programmers and designers find checked exceptions onerous though, so there's a fairly common practice to use unchecked exceptions even in situations where you can expect to encounter an exception from which you can gracefully recover. This approach is less cumbersome but it also requires a little more discipline and thoughtful design because then, developers/designers will get no help from the compiler. They will have to exercise due diligence to ensure that the exception is properly dealt with at some point along the execution path. The designers of the Spring framework favor unchecked exceptions over checked exceptions.
The advice to not catch unchecked exceptions is usually made when advocating for intensive unit testing. The assumption is that rigorous testing will cause these unchecked exceptions to be thrown and cause test failures. The test failures will force the programmers to find the root cause of the problem, which is usually a programming error, during development and fix the code so that there is no possibility of that exception occurring in the production environment.
Junilu Lacar
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
praveen kumaar wrote:
so i would better call it is a bad practice to handle RuntimeException instead of calling it is bad practice to handle Unchecked Exception.
sometimes handling a unchecked exception which a programmer can predict is a good idea.
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Junilu Lacar wrote:Many programmers and designers find checked exceptions onerous though, so there's a fairly common practice to use unchecked exceptions even in situations where you can expect to encounter an exception from which you can gracefully recover.
The Java™ Tutorials wrote:If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.
Daniel Cox wrote:
I don't think that unchecked exceptions are used in situations where you can recover. From what I understand, Spring (unlike JDBC) uses unchecked exceptions for many database-related problems because you cannot recover from these problems.
Consider Paul's rocket mass heater. |