Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-212

[lang] [PATCH] New ExceptionUtils method setCause()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.2
    • None
    • None
    • Operating System: other
      Platform: Other

    • 37574

    Description

      Hi people,

      the purpose of the ExceptionUtils.setCause() method I am proposing is to
      preserve the standard JDK 1.4 exception

      nesting mechanism even when targeting source code for a prior JDK 1.4 version.

      ExceptionUtils.setCause(), which can be thought as the counterpart of
      ExceptionUtils.getCause(), calls via

      introspection on the target Throwable the 2 following methods:

      <Object>.setCause(Throwable)
      <Object>.initCause(Throwable)

      The typical use of ExceptionUtils.setCause() is inside a constructor, as in
      the following example:

      import org.apache.commons.lang.exception.ExceptionUtils;

      public class MyException extends Exception {

      public MyException(String msg)

      { super(msg); }

      public MyException(String msg, Throwable cause)

      { super(msg); ExceptionUtils.setCause(this, cause); }

      }

      I hope this can be useful for whom who are maintaining code that must be
      portable on both the JDK 1.3 and JDK 1.4+

      environments.

      Andrea.

      Attachments

        Activity

          People

            Unassigned Unassigned
            andrea.rombaldi@alice.it Andrea Rombaldi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: