On Tue, May 03, 2011 at 01:08:29AM +0200, Gilles Sadowski wrote: > > > [...] > > >>Consistency implies that *all* exceptions thrown from CM must behave the > > >>same way. I thus propose to add an interface like (maybe a better name?): > > >>--- > > >>interface ContextedException { > > >> void addMessage(Localizable pattern, > > >> Object ... arguments); > > >> void setContext(String key, Object value); > > >> Object getContext(String key); > > >> Set<String> getContextKeys(); > > >> String getMessage(final Locale locale); > > >> String getMessage(final Locale locale, > > >> final String separator); > > >>} > > >>And all CM exceptions will implement this interface. [Instead of > > >>automatically inheriting the behaviour by being subclasses of > > >>"MathRuntimeException".] > > >> > > >I would prefer as stated above to revert to actual RTEs per 2.x > > >behavior. Above would be an improvement, as at least the unexpected > > >RTEs at upgrade would not bite (as they did me), but I see no reason > > >to add this machinery which is no less complex than what we had in > > >2.x. Lets see what others think. > > > > Do the above mean we would have: > > > > public class MathIllegalArgumentException > > extends IllegalArgumentException > > implements ContextedException > > Yes. [Not sure about the name "ContextedException" yet.] > > > If so, then I am OK with this.
I've just been thinking that, as per the concerns raised in the thread about interface overuse, it would be better to create a "thin" interface: --- public interface ExceptionContextProvider { /** * @return the context data structure that enables the customization of * the error message. */ ExceptionContext getContext(); } --- Then, all CM exceptions would be like --- public class MathIllegalArgumentException extends IllegalArgumentException implements ExceptionContextProvider { // ... } --- And the (concrete) class "ExceptionContext" would contain the implementation required for the "map" feature: --- public class ExceptionContext { void addMessage(Localizable pattern, Object ... arguments); void setValue(String key, Object value); Object getValue(String key); Set<String> getContextKeys(); String getMessage(final Locale locale); String getMessage(final Locale locale, final String separator); } --- It would thus be less disruptive if a method is added later in the "ExceptionContext" utility. OK? Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org