hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind TestApplicationRuntimeException.java
Date Mon, 01 Nov 2004 16:38:03 GMT
hlship      2004/11/01 08:38:03

  Modified:    .        status.xml
               framework/src/java/org/apache/hivemind
                        ApplicationRuntimeException.java
  Added:       framework/src/test/org/apache/hivemind
                        TestApplicationRuntimeException.java
  Log:
  Change ApplicationRuntimeException to includethe location of the exception, if known, in
toString() (used by printStackTrace()).
  
  Revision  Changes    Path
  1.72      +4 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- status.xml	1 Nov 2004 01:55:47 -0000	1.71
  +++ status.xml	1 Nov 2004 16:38:03 -0000	1.72
  @@ -71,6 +71,10 @@
         <action type="add" dev="HLS">
           Move some logic related to primitive Java types and arrays from Tapestry directly
into DefaultClassResolver.
         </action>
  +      <action type="update" dev="HLS">
  +        ApplicationRuntimeException will now display the location (if known) as part of
its toString() method, making it
  +        much easier to track down problems in stack traces (especially deeply nested ones).
  +      </action>
       </release>
   
      <release version="1.0" date="Sep 22 2004">
  
  
  
  1.4       +37 -18    jakarta-hivemind/framework/src/java/org/apache/hivemind/ApplicationRuntimeException.java
  
  Index: ApplicationRuntimeException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/ApplicationRuntimeException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ApplicationRuntimeException.java	19 Aug 2004 13:25:58 -0000	1.3
  +++ ApplicationRuntimeException.java	1 Nov 2004 16:38:03 -0000	1.4
  @@ -15,19 +15,20 @@
   package org.apache.hivemind;
   
   /**
  - *  General wrapper for any exception (normal or runtime) that may occur during
  - *  runtime processing for the application.  This is exception is used
  - *  when the intent is to communicate a low-level failure to the user or
  - *  developer; it is not expected to be caught.  The {@link #getRootCause() rootCause}
  - *  property is a <em>nested</em> exception.
  - *
  - *  @author Howard Lewis Ship
  + * General wrapper for any exception (normal or runtime) that may occur during runtime
processing
  + * for the application. This is exception is used when the intent is to communicate a low-level
  + * failure to the user or developer; it is not expected to be caught. The
  + * {@link #getRootCause() rootCause}property is a <em>nested</em> exception.
  + * 
  + * @author Howard Lewis Ship
    */
   
   public class ApplicationRuntimeException extends RuntimeException implements Locatable
   {
       private Throwable _rootCause;
  +
       private transient Location _location;
  +
       private transient Object _component;
   
       public ApplicationRuntimeException(Throwable rootCause)
  @@ -45,18 +46,16 @@
           this(message, null, null, rootCause);
       }
   
  -    public ApplicationRuntimeException(
  -        String message,
  -        Object component,
  -        Location location,
  -        Throwable rootCause)
  +    public ApplicationRuntimeException(String message, Object component, Location location,
  +            Throwable rootCause)
       {
           super(message);
   
           _rootCause = rootCause;
           _component = component;
   
  -        _location = HiveMind.findLocation(new Object[] { location, rootCause, component
});
  +        _location = HiveMind.findLocation(new Object[]
  +        { location, rootCause, component });
       }
   
       public ApplicationRuntimeException(String message, Location location, Throwable rootCause)
  @@ -79,13 +78,33 @@
           return _component;
       }
   
  -	/**
  -	 * This method is for compatibility with JDK 1.4 ... under 1.4, this will look like
  -	 * an override, allowing <code>printStackTrace()</code> to descending into
the root cause
  -	 * exception and print its stack trace too.
  -	 */
  +    /**
  +     * This method is for compatibility with JDK 1.4 ... under 1.4, this will look like
an override,
  +     * allowing <code>printStackTrace()</code> to descending into the root
cause exception and
  +     * print its stack trace too.
  +     */
       public Throwable getCause()
       {
           return _rootCause;
  +    }
  +
  +    /**
  +     * Overrides the default implementation of <code>toString</code>, suffixing
the normal result
  +     * with the {@link #getLocation() location}of the exception (if non null). Example:
  +     * <code>org.apache.hivemind.ApplicationRuntimeException: Exception Message [file:foo/bar/baz,
line 13]</code>.
  +     * 
  +     * @since 1.1
  +     */
  +    public String toString()
  +    {
  +        if (_location == null)
  +            return super.toString();
  +
  +        StringBuffer buffer = new StringBuffer(super.toString());
  +        buffer.append(" [");
  +        buffer.append(_location);
  +        buffer.append("]");
  +
  +        return buffer.toString();
       }
   }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/TestApplicationRuntimeException.java
  
  Index: TestApplicationRuntimeException.java
  ===================================================================
  //Copyright 2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.hivemind;
  
  import org.apache.hivemind.test.HiveMindTestCase;
  
  /**
   * Tests some features of {@link org.apache.hivemind.ApplicationRuntimeException}.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestApplicationRuntimeException extends HiveMindTestCase
  {
      public void testToStringNoLocation()
      {
          ApplicationRuntimeException ex = new ApplicationRuntimeException("some message");
  
          assertEquals("org.apache.hivemind.ApplicationRuntimeException: some message", ex.toString());
      }
  
      public void testToStringWithLocation()
      {
          Location l = fabricateLocation(22);
  
          ApplicationRuntimeException ex = new ApplicationRuntimeException("my message", l,
null);
  
          assertEquals(
                  "org.apache.hivemind.ApplicationRuntimeException: my message [" + l + "]",
                  ex.toString());
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message