Commons Lang
  1. Commons Lang
  2. LANG-212

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

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      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.

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrea Rombaldi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development