Well, I’ve been doing tons of reading on exception handling to try and develop a standard set of practices. I’ve got two immediate problems that I need to address and haven’t found much advice on:

1. Exceptions Crossing Tier Boundaries: Many of our systems are n-Tier and exceptions visible in the most remote layers aren’t necessarily available in the presentation tier. What to do?

I want to preserve the stack trace if at all possible, so I’m thinking of wrapping just the stack trace in another (presentation-tier-visible) exception and passing that on.

Alternatively, I can just log the exception (and stack trace), then rethrow a brand new exception to the client (with some sort of user-meaningful error message).

2. Externalising Error Codes and Messages: From a helpdesk point of view, it would be nice to be able to associate a numeric id with each exception. Then a client can report “Error 67: Internal Data Store Problems” appears on my screen, but the helpdesk knows that error 67 actually relates to incorrect database credentials, or whatever.

My initial thoughts are maybe to use something like a ResourceBundle, but maybe some custom descendant like a JDBCResourceBundle - where I could keep all my messages in a database (except for if the database fails ;-). My code could then pass a constant like DB_CREDENTIAL_FAILURE to the bundle and retrieve a nice-ish message like “Internal Data Store problems have been encountered talking to server {0}.” And do some nice MessageFormat calls to tidy things up.

Anyways, I’m interested to hear what you guys are doing with Cross-Tier exceptions and externalising Error strings. All ideas welcome.