commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Schaible <joerg.schai...@gmx.de>
Subject Re: [lang] Time for RC3?
Date Sat, 02 Jul 2011 14:28:57 GMT
Hi,

Henri Yandell wrote:

> These are the current blocking items in play afaik:
> 
> * Email thread - what else should implement Formattable?
> * LANG-696/Email thread - getShortName. What to do with the (String)
> variant. Remove others.
> * Email thread - Validate method naming

Can somebody else give the ContextedException stuff a review? I used in the 
meanwhile a copy of it in a project, but a method name is bugging me.

What's it about? The exception provides a context for additional 
information, just think of a map with key/value pairs. The problem that it 
solves:

Instead of writing:

throw new MyCommunicationException("The connection to " + host + ':' + port 
+ " failed for " + user + " because of invalid credentials");

you have:

throw new MyCommunicationException("Invalid credentials for 
connection").addValue("host", host).addValue("port", port).addValue("user", 
user);

And you're able to enrich the context in a bigger scope:

try {
...
} (catch MyCommunicationException e) {
  throw e.addValue("Module", "backup");
}

Fine so far. The values are properly formatted in table form in case of a 
message and you may even access the individual values. A problem arises in 
recursive algorithms (e.g. SAX Handler) with:

try {
...
} (catch MyException e) {
  throw e.addValue("Current Handler", handler.class.getName())
    .addValue("Current Line", line);
}

This would normally clobber the "Current Handler" in a nested handler 
situation. Our implementation will therefore detect the key clash and add 
the new value with key "Current Handler[1]" (and will increase the index for 
more values). However, the current line in the processed XML is always the 
same and does not change, but would be added over and over again for each 
recursive step.

Therefore the ExceptionContext defines the method "replaceValue(key, value)" 
... and this is bugging me, since for me it is "setValue(key, value)". 
Typically *I* would use setValue for the normal case and only in recursive 
situations addValue. Can somebody review this interface and also the method 
documentation, because *I* have a clear idea what add/set should do, but the 
method description gives a lot of possibilities about its purpose and how it 
can be implemented. What do you think about this API?

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message