|
Re: Analyze this!
|
Posted: Nov 14, 2003 12:33 AM
|
|
I programmed in C/C++ for about 10 years prior to using Java, and not having a reminder to catch an exception is a significant problem. I aplaud James for attempting to correct this problem. It is fairly obvious that interface issues can be solved by nesting exceptions or even converting them to runtime exceptions. I believe the only major issue with checked exceptions that cannot be overcome fairly easily is the empty catch clause. I actually feel that James would be doing himself more justice to acknowledge this as a real world problem as opposed to seemingly implying that the education system is at fault. Often times contractors are hired by companies to do short term work under tremendous time pressures. This is going to happen whether or not our education system encourages it, due to haste and or laziness. I know that for myself the empty catch clause is not a problem because I and my close colleagues do not use empty catch clauses without a great deal of scrutinization of the situation at hand. Checked exceptions have VASTLY improved error checking in my programs.
I have a partial workaround and a proposed solution for those who are having problems. Unfortunately the solution would not be backwards compatible.
The workaround is to search inherited source for empty catch clauses and DO SOMETHING ABOUT THEM! You have bugs in your source if error checking isn't being handled! Of course this would not work if you purchased a third party library for which you do not have the source.
The proposed solution would be to have the empty catch clause convert all exceptions it catches into runtime exceptions and rethrow them i.e. the exact behavior you would have had without the checked exceptions in place. Yes this allows sloppy or lazy programmers to circumvent the checked exceptions mechanism but they are doing this already with far worse consequences. In addition, it allows meticulous programmers to still use checked exceptions and it eliminates the possibility of the horrendous down stream bugs that can be caused by an empty catch clause, the same bugs which should be acknowledged by the creators of the checked exception mechanism as highly problematic. If one truly wanted and needed an explicit empty catch clause that did nothing, a keyword could be added to the language such as explicitempty.
catch( IOException ex ){ explicitempty; }
The truly lazy programmer will not go to the effort of typing in "explicitempty;" especially if the recommended behavior is to leave the clause empty.
In short, for those who are already not using the checked exceptions mechanism, the behavior would default back to that of not having checked exceptions. However, the programmer would have to consiously acknowledge the exception even if they only choose to convert it into a runtime exception.
|
|