Tuesday, May 18, 2004

Common Problems

Recently I concluded an engagement which involved reviewing and commenting on someone's Java code. While submitting the results, the discussion turned towards some common problems. Interestingly we are grappling with the same problem at my work place too. How do you do error handling, good exception handling with effective user feedback?

It all drills down to being able to identify the exact cause of the problem and to be able to suggest solutions to it. It so turns our that this seems to be quite difficult to do.

Where does the difficulty lie? I think the difficulty builds over time. e.g.
If I write some code that does a file copy I will end up doing the following

public void copy(InputStream src, OutputStream dest) throws IOException;

What is wrong with this code? A bunch of things and I do not know what to fix in it.
IOException has about 20 different direct sub-classes. Out of which this operation could potentially raise over half of them. Most implementations handle this by simply catching it and if they do not ignore it (god forbid) they just show an IO Error message to the user. If you have a Java aware user, well good for you (my experience with Java aware developers are that they do not understand these exceptions anyway) but for a Java unaware user what do you say?
The only way you can provide effective feedback is to catch every single type of exception and try and figure out what it means. Would you find in yourself the motivation to do that?. You are still left with a bunch of IOExceptions ranging from not enough diskspace to remote file system is not accessible, permission problems etc. You are still constrained by the effective user messages of your library.

How does one solve this problem? Our customer asked us if we knew of any third party exception handling package that he could download. Now thats a killer application.


Check out who all are arguing about it too...
gosling@artima
Hejlsberg@artima

2 comments:

Sachin said...

Here's an excellent article about this problem

Anonymous said...

Hey, you have a great blog here! I'm definitely going to bookmark you! Get free
Traffic to your site/blog. It will Improve your page rank and it's free.
Go and check it out if you get time :-)