This subject seems to be rather straightforward, correct? :)
I have been involved during the last weeks in situations connected to this subject, and I thought I would share my thoughts on the matter.
At the first sight, one might think that programming around java exceptions could be considered tedious, since you more or less have to handle them or delegate their handling to the calling software layers.
I would think otherwise. I am of the opinion that the Java exceptions have been designed well originally. While slightly verbose, their proper handling could greatly ease the maintenance, bug finding and monitoring of java programs.
I have experienced this first hand; while working with software written in such a way that prevented proper management and logging of java exceptions, I found that it is much harder to find the errors in the programs written by others - without knowing the code base, it was difficult to fix bugs or alter the existing code - I often had to revert to old style debugging. It shouldn't be that difficult - one look on the stacktrace usually should be enough to understand the situation.
On the checked versus unchecked exceptions subject. I found that it usually is difficult to predict _many_ of the situations that might appear while the program is running, and this is due to the inherent complexities of the conditions and situations that might appear; For this reason alone, I rather prefer to use checked exceptions as much as possible, that could be handled in a way during the program execution. This approach usually allows the program to recover from additional previously unconsidered situations, possibly with the user help.
One example is the NullPointerException: while unchecked, it might appear in many situations. Some of them, usually, could be corrected by the user itself, so it might be worth giving the user a chance to do so. For example, in case of missing (config) files and others. Therefore, it might be worth handling this exception in some cases within the java program itself, possibly by employing the usage of checked exceptions instead.
Niciun comentariu:
Trimiteți un comentariu