Andrea: Thanks for the clarification. Code and tests tweaked and committed with an extra test method.
Gary > -----Original Message----- > From: Andrea Rombaldi [mailto:[EMAIL PROTECTED] > Sent: Wednesday, January 04, 2006 1:48 PM > To: Jakarta Commons Developers List > Subject: Re: [lang] [PATCH] new ExceptionUtils.setCause() method > > Hallo Gary, > > the main reason I wrote ExceptionUtils.setCause() is to make my logs the > more readable as possibile depending on the underlying JRE, so the > different > behavior between JRE < 1.4 and >= 1.4 is by design. > > I agree with you that extending NestableException, NestableError, > NestableRuntimeException *is the best way* to accomplish this task. > > But in those cases when the developer is dealing with already defined > Exceptions that are not subclassed from Nestable* the use of > ExceptionUtils.setCause() can be useful to avoid the implementation of the > Nestable interface and get the portability to JRE >= 1.4, as in the > following example: > > > import org.apache.commons.codec; > import org.apache.commons.log; > > public class MyEncoder implements Encoder { > > public Object encode(Object pObject) throws EncoderException { > Object result = null; > try { > InputStream in = .... > try { > // omissis > } finally { > in.close(); > } > } catch (IOException ioe) { > EncoderException e = new ExcoderException("Encode failed due > to > an I/O error"); > ExceptionUtils.setCause(e, ioe); > throw e; > } > return result; > } > > protected static Log LOG = LogFactory.getLog(MyEncoder.class); > > public static void main(String[] args) { > MyEncoder enc = new MyEncoder(); > try { > System.out.println(enc.encode("test")); > LOG.info("encode() succeeded"); > } catch (EncoderException e) { > LOG.error("encode() failed", e); > } > } > > } > > Ciao, > Andrea. > > > PS: the simple example I provided could open a debate: why not including > commons-lang in the other commons-* components and leverage the power of > lang.builder.*, lang.enums.*, lang.exception.* packages and so on? > IMHO in most cases the commons-lang code is more reliable than the > equivalent ad-doc imported or written code in the other commons-* > packages. > :-) > > > ----- Original Message ----- > From: "Gary Gregory" <[EMAIL PROTECTED]> > To: "Jakarta Commons Developers List" <[email protected]> > Sent: Wednesday, January 04, 2006 9:00 AM > Subject: RE: [lang] [PATCH] new ExceptionUtils.setCause() method > > > Hello Andrea: > > I have your patch installed on my machine but I want to make sure I > understand the intent. In your example: > > > public class MyException extends Exception { > > public MyException(String msg) { > super(msg); > } > > public MyException(String msg, Throwable cause) { > super(msg); > ExceptionUtils.setCause(this, cause); > } > > } > > If this code runs in a JRE >= 1.4 , the cause is set in the target. > > If this code runs in a JRE < 1.4, nothing happens. > > So the code is portable but the behavior is different. > > Is the intent to write code in a JRE < 1.4 that will behave OK on a JRE > >= 1.4? > > Why not subclass NestableException and get the portability AND the > proper behavior? > > Thanks, > Gary > > > -----Original Message----- > > From: Andrea Rombaldi [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, January 03, 2006 10:44 AM > > To: Jakarta Commons Developers List > > Subject: Re: [lang] [PATCH] new ExceptionUtils.setCause() method > > > > Hi, > > > > this is just a reminder for my trivial patch :-) > > > > Ciao, > > Andrea. > > > > > > > DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG* > > > RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT > > > <http://issues.apache.org/bugzilla/show_bug.cgi?id=37574>. > > > ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND* > > > INSERTED IN THE BUG DATABASE. > > > > > > http://issues.apache.org/bugzilla/show_bug.cgi?id=37574 > > > > > > > > > > > > > > > > > > ------- Additional Comments From [EMAIL PROTECTED] 2005-12-06 > > > 01:19 ------- > > > I'll try to take a look this week. > > > > > > -- > > > Configure bugmail: > > > http://issues.apache.org/bugzilla/userprefs.cgi?tab=email > > > ------- You are receiving this mail because: ------- > > > You reported the bug, or are watching the reporter. > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
