Author: wglass
Date: Sun Nov  5 00:56:58 2006
New Revision: 471381

URL: http://svn.apache.org/viewvc?view=rev&rev=471381
Log:
Removed generic "Exception" from throws for Template class and most Node 
classes.  
In response to VELOCITY-436.  There's a danger of a change to an
API call since this involves method signatures, but the only interface that 
seems
relevant is Node.init (used when defining custom directives).
Since we are removing Exception and adding TemplateInitException
this seems to work.

Added:
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
   (with props)
Removed:
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/DirectiveInitException.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/exception/ReferenceException.java
Modified:
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/Template.java
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/Velocity.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Literal.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTText.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/Template.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/Template.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/Template.java 
(original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/Template.java 
Sun Nov  5 00:56:58 2006
@@ -20,6 +20,7 @@
  */
 
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
@@ -30,6 +31,8 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.node.SimpleNode;
 import org.apache.velocity.runtime.resource.Resource;
@@ -58,7 +61,7 @@
  */
 public class Template extends Resource
 {
-    private Exception errorCondition = null;
+    private VelocityException errorCondition = null;
 
     /** Default constructor */
     public Template()
@@ -73,11 +76,10 @@
      *          from any available source.
      * @throws ParseErrorException if template cannot be parsed due
      *          to syntax (or other) error.
-     * @throws Exception some other problem, should only be from
-     *          initialization of the template AST.
+     * @throws IOException problem reading input stream
      */
     public boolean process()
-        throws ResourceNotFoundException, ParseErrorException, Exception
+        throws ResourceNotFoundException, ParseErrorException, IOException
     {
         data = null;
         InputStream is = null;
@@ -135,6 +137,11 @@
                 errorCondition =  new ParseErrorException( pex );
                 throw errorCondition;
             }
+            catch ( TemplateInitException pex )
+            {
+                errorCondition = new ParseErrorException( pex );
+                throw errorCondition;
+            }
             /**
              * pass through runtime exceptions
              */
@@ -142,15 +149,6 @@
             {
                 throw e;
             }
-            catch( Exception e )
-            {
-                /*
-                 *  who knows?  Something from initDocument()
-                 */
-
-                errorCondition = e;
-                throw e;
-            }
             finally
             {
                 /*
@@ -175,10 +173,10 @@
      *  dependant upon context, but we need to let the
      *  init() carry the template name down throught for VM
      *  namespace features
-     * @throws Exception When a problem occurs during the document 
initialization.
+     * @throws TemplateInitException When a problem occurs during the document 
initialization.
      */
     public void initDocument()
-        throws Exception
+    throws TemplateInitException
     {
         /*
          *  send an empty InternalContextAdapter down into the AST to 
initialize it
@@ -216,9 +214,6 @@
      * The AST node structure is merged with the
      * context to produce the final output.
      *
-     * Throws IOException if failure is due to a file related
-     * issue, and Exception otherwise
-     *
      *  @param context Conext with data elements accessed by template
      *  @param writer output writer for rendered template
      *  @throws ResourceNotFoundException if template not found
@@ -226,10 +221,10 @@
      *  @throws ParseErrorException if template cannot be parsed due
      *          to syntax (or other) error.
      *  @throws MethodInvocationException When a method on a referenced object 
in the context could not invoked.
-     *  @throws  Exception  anything else.
+     *  @throws IOException  Might be thrown while rendering.
      */
     public void merge( Context context, Writer writer)
-        throws ResourceNotFoundException, ParseErrorException, 
MethodInvocationException, Exception
+        throws ResourceNotFoundException, ParseErrorException, 
MethodInvocationException, IOException
     {
         /*
          *  we shouldn't have to do this, as if there is an error condition,
@@ -276,8 +271,8 @@
             String msg = "Template.merge() failure. The document is null, " +
                 "most likely due to parsing error.";
 
-            rsvc.getLog().error(msg);
-            throw new Exception(msg);
+            throw new RuntimeException(msg);
+
         }
     }
 }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/Velocity.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/Velocity.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/Velocity.java 
(original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/Velocity.java 
Sun Nov  5 00:56:58 2006
@@ -36,6 +36,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeSingleton;
 import org.apache.velocity.runtime.log.Log;
@@ -276,6 +277,10 @@
         {
             throw  new ParseErrorException( pex );
         }
+        catch (TemplateInitException pex)
+        {
+            throw  new ParseErrorException( pex );
+        }
 
         /*
          * now we want to init and render
@@ -293,6 +298,17 @@
                 try
                 {
                     nodeTree.init( ica, RuntimeSingleton.getRuntimeServices() 
);
+                }
+                catch (TemplateInitException pex)
+                {
+                    throw  new ParseErrorException( pex );
+                }
+                /**
+                 * pass through application level runtime exceptions
+                 */
+                catch( RuntimeException e )
+                {
+                    throw e;
                 }
                 catch( Exception e )
                 {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/app/VelocityEngine.java
 Sun Nov  5 00:56:58 2006
@@ -36,9 +36,9 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeInstance;
-import org.apache.velocity.runtime.directive.DirectiveInitException;
 import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.node.SimpleNode;
@@ -310,6 +310,10 @@
         {
             throw  new ParseErrorException( pex );
         }
+        catch (TemplateInitException pex)
+        {
+            throw  new ParseErrorException( pex );
+        }
 
         /*
          * now we want to init and render
@@ -328,16 +332,16 @@
                 {
                     nodeTree.init( ica, ri );
                 }
+                catch (TemplateInitException pex)
+                {
+                    throw  new ParseErrorException( pex );
+                }
                 /**
                  * pass through application level runtime exceptions
                  */
                 catch( RuntimeException e )
                 {
                     throw e;
-                }
-                catch (DirectiveInitException pex)
-                {
-                    throw  new ParseErrorException( pex );
                 }
                 catch(Exception e)
                 {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/ParseErrorException.java
 Sun Nov  5 00:56:58 2006
@@ -102,6 +102,37 @@
         }
     }
 
+    /**
+     * Create a ParseErrorException with the given ParseException.
+     *
+     * @param pex the parsing exception
+     */
+    public ParseErrorException(VelocityException pex)
+    {
+        super(pex.getMessage());
+
+        // Don't use a second C'tor, TemplateParseException is a subclass of
+        // ParseException...
+        if (pex instanceof ExtendedParseException)
+        {
+            ExtendedParseException xpex = (ExtendedParseException) pex;
+
+            columnNumber = xpex.getColumnNumber();
+            lineNumber = xpex.getLineNumber();
+            templateName = xpex.getTemplateName();
+        }
+        else if (pex.getWrappedThrowable() instanceof ParseException)
+        {
+            ParseException pex2 = (ParseException) pex.getWrappedThrowable();
+
+            if (pex2.currentToken != null && pex2.currentToken.next != null)
+            {
+                columnNumber = pex2.currentToken.next.beginColumn;
+                lineNumber = pex2.currentToken.next.beginLine;
+            }
+        }
+    }
+
 
     /**
      * Create a ParseErrorRuntimeException with the given message and info

Added: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java?view=auto&rev=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
 (added)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
 Sun Nov  5 00:56:58 2006
@@ -0,0 +1,91 @@
+package org.apache.velocity.exception;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.    
+ */
+
+import org.apache.velocity.runtime.parser.ParseException;
+
+/**
+ * Exception generated to indicate parse errors caught during
+ * directive initialization (e.g. wrong number of arguments)
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class TemplateInitException extends VelocityException 
+        implements ExtendedParseException
+{
+    private final String templateName;
+    private final int col;
+    private final int line;
+    
+    /**
+     * Version Id for serializable
+     */
+    private static final long serialVersionUID = -4985224672336070621L;
+
+    public TemplateInitException(final String msg, 
+            final String templateName, final int col, final int line)
+    {
+        super(msg);
+        this.templateName = templateName;
+        this.col = col;
+        this.line = line;
+    }
+
+    public TemplateInitException(final String msg, ParseException 
parseException,
+            final String templateName, final int col, final int line)
+    {
+        super(msg,parseException);
+        this.templateName = templateName;
+        this.col = col;
+        this.line = line;
+    }
+
+    /**
+     * Returns the Template name where this exception occured.
+     * @return the template name
+     */
+    public String getTemplateName()
+    {
+        return templateName;
+    }
+
+    /**
+     * Returns the line number where this exception occured.
+     * @return the line number
+     */
+    public int getLineNumber()
+    {
+        return line;
+    }
+
+    /**
+     * Returns the column number where this exception occured.
+     * @return the line number
+     */
+    public int getColumnNumber()
+    {
+        return col;
+    }
+
+    
+    
+    
+}

Propchange: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/TemplateInitException.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Directive.java
 Sun Nov  5 00:56:58 2006
@@ -30,6 +30,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 
 
 /**
@@ -94,11 +95,11 @@
      * @param rs
      * @param context
      * @param node
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public void init( RuntimeServices rs, InternalContextAdapter context,
                       Node node)
-        throws Exception
+        throws TemplateInitException
     {
         rsvc = rs;
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
 Sun Nov  5 00:56:58 2006
@@ -29,6 +29,7 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.parser.node.ASTReference;
@@ -300,10 +301,10 @@
      * @param rs
      * @param context
      * @param node
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public void init(RuntimeServices rs, InternalContextAdapter context, Node 
node)
-        throws Exception
+        throws TemplateInitException
     {
         super.init(rs, context, node);
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Include.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
 Sun Nov  5 00:56:58 2006
@@ -26,6 +26,7 @@
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.parser.ParserTreeConstants;
@@ -96,11 +97,11 @@
      * @param rs
      * @param context
      * @param node
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public void init(RuntimeServices rs, InternalContextAdapter context,
                      Node node)
-        throws Exception
+        throws TemplateInitException
     {
         super.init( rs, context, node );
 
@@ -172,6 +173,9 @@
      *  @param context valid context so we can render References
      *  @param writer output Writer
      *  @return boolean success or failure.  failures are logged
+     *  @exception IOException
+     *  @exception MethodInvocationException
+     *  @exception ResourceNotFoundException
      */
     private boolean renderOutput( Node node, InternalContextAdapter context,
                                   Writer writer )
@@ -267,6 +271,9 @@
      *  Puts a message to the render output stream if ERRORMSG_START / END
      *  are valid property strings.  Mainly used for end-user template
      *  debugging.
+     *  @param writer
+     *  @param msg
+     *  @throws IOException
      */
     private void outputErrorToStream( Writer writer, String msg )
         throws IOException

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Literal.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Literal.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Literal.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Literal.java
 Sun Nov  5 00:56:58 2006
@@ -23,6 +23,7 @@
 import java.io.Writer;
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.parser.node.Node;
 
@@ -63,11 +64,11 @@
      * @param rs
      * @param context
      * @param node
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public void init(RuntimeServices rs, InternalContextAdapter context,
                      Node node)
-        throws Exception
+        throws TemplateInitException
     {
         super.init( rs, context, node );
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
 Sun Nov  5 00:56:58 2006
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 
 import org.apache.velocity.runtime.parser.node.Node;
 import org.apache.velocity.runtime.parser.node.NodeUtils;
@@ -101,7 +102,7 @@
      */
     public void init(RuntimeServices rs, InternalContextAdapter context,
                      Node node)
-       throws Exception
+       throws TemplateInitException
     {
         super.init(rs, context, node);
 
@@ -225,6 +226,7 @@
      * list.  It's expected to include the block node tree (for the
      * macro body).
      * @param rsvc For debugging purposes only.
+     * @return array of arguments
      */
     private static String[] getArgArray(Node node, RuntimeServices rsvc)
     {
@@ -278,6 +280,8 @@
 
     /**
      *  Returns an array of the literal rep of the AST
+     *  @param rootNode
+     *  @return list of Strings
      */
     private static List getASTAsStringArray(Node rootNode)
     {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 Sun Nov  5 00:56:58 2006
@@ -29,6 +29,7 @@
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.context.VMContext;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.parser.ParserTreeConstants;
@@ -231,10 +232,10 @@
      * @param rs
      * @param context
      * @param node
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public void init( RuntimeServices rs, InternalContextAdapter context, Node 
node)
-       throws Exception
+       throws TemplateInitException
     {
         super.init( rs, context, node );
 
@@ -283,7 +284,7 @@
                  *  indicate col/line assuming it starts at 0 - this will be
                  *  corrected one call up
                  */
-                throw new DirectiveInitException(errormsg,
+                throw new TemplateInitException(errormsg,
                         context.getCurrentTemplateName(),
                         0,
                         0);
@@ -326,6 +327,7 @@
     /**
      *   parses the macro.  We need to do this here, at init time, or else
      *   the local-scope template feature is hard to get to work :)
+     *   @param callArgs
      */
     private void parseTree( String[] callArgs )
     {
@@ -403,6 +405,8 @@
 
     /**
      *   gets the args to the VM from the instance-use AST
+     *   @param node
+     *   @return array of arguments
      */
     private String[] getArgArray( Node node )
     {

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
 Sun Nov  5 00:56:58 2006
@@ -19,16 +19,16 @@
  * under the License.    
  */
 
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 import org.apache.velocity.runtime.parser.Token;
-import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.MethodInvocationException;
-
-import java.io.IOException;
-import java.io.Writer;
 
 /**
  *  Represents all comments...
@@ -72,10 +72,8 @@
      * @param context
      * @param data
      * @return The data object.
-     * @throws Exception
      */
     public Object init(InternalContextAdapter context, Object data)
-            throws Exception
     {
         Token t = getFirstToken();
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
 Sun Nov  5 00:56:58 2006
@@ -27,10 +27,12 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.directive.Directive;
-import org.apache.velocity.runtime.directive.DirectiveInitException;
+import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
+import org.apache.velocity.util.ExceptionUtils;
 
 /**
  * This class is responsible for handling the pluggable
@@ -82,7 +84,7 @@
      * @see 
org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
     public Object init( InternalContextAdapter context, Object data)
-        throws Exception
+    throws TemplateInitException
     {
         super.init( context, data );
 
@@ -94,9 +96,26 @@
         {
             isDirective = true;
 
-            directive = (Directive) parser.getDirective( directiveName )
-                .getClass().newInstance();
-
+            try
+            {
+                directive = (Directive) parser.getDirective( directiveName )
+                    .getClass().newInstance();
+            } 
+            catch (InstantiationException e)
+            {
+                throw ExceptionUtils.createRuntimeException("Couldn't 
initialize " +
+                        "directive of class " +
+                        
parser.getDirective(directiveName).getClass().getName(),
+                        e);
+            }
+            catch (IllegalAccessException e)
+            {
+                throw ExceptionUtils.createRuntimeException("Couldn't 
initialize " +
+                        "directive of class " +
+                        
parser.getDirective(directiveName).getClass().getName(),
+                        e);
+            }
+                
             directive.init(rsvc, context,this);
 
             directive.setLocation( getLine(), getColumn() );
@@ -118,9 +137,10 @@
             /**
              * correct the line/column number if an exception is caught
              */
-            catch (DirectiveInitException die)
+            catch (TemplateInitException die)
             {
-                throw new DirectiveInitException(die.getMessage(),
+                throw new TemplateInitException(die.getMessage(),
+                        (ParseException) die.getWrappedThrowable(),
                         die.getTemplateName(),
                         die.getColumnNumber() + getColumn(),
                         die.getLineNumber() + getLine());

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEscape.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEscape.java
 Sun Nov  5 00:56:58 2006
@@ -71,7 +71,6 @@
      * @see 
org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
     public Object init( InternalContextAdapter context, Object data)
-        throws Exception
     {
         ctext =  val.toCharArray();
         return data;

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
 Sun Nov  5 00:56:58 2006
@@ -19,12 +19,13 @@
  * under the License.    
  */
 
+import java.math.BigDecimal;
+
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 
-import java.math.BigDecimal;
-
 
 /**
  * Handles floating point numbers.  The value will be either a Double
@@ -70,10 +71,10 @@
      * @param context
      * @param data
      * @return The data object.
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public Object init( InternalContextAdapter context, Object data)
-        throws Exception
+        throws TemplateInitException
     {
         /*
          *  init the tree correctly

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
 Sun Nov  5 00:56:58 2006
@@ -24,6 +24,7 @@
 import org.apache.velocity.app.event.EventHandlerUtil;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 import org.apache.velocity.util.introspection.Info;
@@ -87,10 +88,10 @@
      * @param context
      * @param data
      * @return The data object.
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public  Object init(InternalContextAdapter context, Object data)
-        throws Exception
+        throws TemplateInitException
     {
         super.init(context, data);
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
 Sun Nov  5 00:56:58 2006
@@ -20,6 +20,7 @@
  */
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 
@@ -66,7 +67,7 @@
      * @see 
org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
     public Object init( InternalContextAdapter context, Object data)
-        throws Exception
+        throws TemplateInitException
     {
         /*
          *  init the tree correctly

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
 Sun Nov  5 00:56:58 2006
@@ -26,6 +26,7 @@
 import org.apache.velocity.app.event.EventHandlerUtil;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 import org.apache.velocity.util.introspection.Info;
@@ -86,10 +87,10 @@
      * @param context
      * @param data
      * @return The init result
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public Object init(  InternalContextAdapter context, Object data)
-        throws Exception
+        throws TemplateInitException
     {
         super.init(  context, data );
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
 Sun Nov  5 00:56:58 2006
@@ -27,8 +27,8 @@
 import org.apache.velocity.context.Context;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.exception.ReferenceException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 import org.apache.velocity.runtime.parser.Token;
@@ -101,7 +101,7 @@
      * @see 
org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
     public Object init(InternalContextAdapter context, Object data)
-        throws Exception
+    throws TemplateInitException
     {
         /*
          *  init our children
@@ -449,8 +449,13 @@
 
         if (result == null)
         {
-            log.error(new ReferenceException("reference set : template = "
-                      + context.getCurrentTemplateName(), this));
+            String msg = "reference set : template = "
+                + context.getCurrentTemplateName() +
+                " [line " + getLine() + ",column " +
+                getColumn() + "] : " + literal() +
+                " is not a valid reference.";
+            
+            log.error(msg);
             return false;
         }
 
@@ -464,8 +469,14 @@
 
             if (result == null)
             {
-                log.error(new ReferenceException("reference set : template = "
-                          + context.getCurrentTemplateName(), this));
+                String msg = "reference set : template = "
+                    + context.getCurrentTemplateName() +
+                    " [line " + getLine() + ",column " +
+                    getColumn() + "] : " + literal() +
+                    " is not a valid reference.";
+                
+                log.error(msg);
+
                 return false;
             }
         }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
 Sun Nov  5 00:56:58 2006
@@ -25,6 +25,7 @@
 import org.apache.velocity.app.event.EventHandlerUtil;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
@@ -79,10 +80,10 @@
      * @param context
      * @param data
      * @return Init result.
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public Object init(InternalContextAdapter context, Object data)
-            throws Exception
+    throws TemplateInitException
     {
         /*
          *  init the tree correctly

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
 Sun Nov  5 00:56:58 2006
@@ -28,7 +28,9 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 
@@ -73,10 +75,10 @@
      * @param context
      * @param data
      * @return Init result.
-     * @throws Exception
+     * @throws TemplateInitException
      */
     public Object init(InternalContextAdapter context, Object data)
-        throws Exception
+    throws TemplateInitException
     {
         /*
          *  simple habit...  we prollie don't have an AST beneath us
@@ -152,9 +154,20 @@
              *  Also, do *not* dump the VM namespace for this template
              */
 
-            nodeTree  = rsvc.parse(br, (context != null) ?
-                    context.getCurrentTemplateName() : "StringLiteral", false);
-
+            try 
+            {
+                nodeTree  = rsvc.parse(br, (context != null) ?
+                        context.getCurrentTemplateName() : "StringLiteral", 
false);
+            }
+            catch (ParseException e)
+            {
+                throw new TemplateInitException("Problem parsing String 
literal.",
+                        e,
+                        (context != null) ? context.getCurrentTemplateName() : 
"StringLiteral",
+                        getColumn(),
+                        getLine() );
+            }
+                
             /*
              *  init with context. It won't modify anything
              */

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTText.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTText.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTText.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTText.java
 Sun Nov  5 00:56:58 2006
@@ -23,6 +23,7 @@
 import java.io.IOException;
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
 import org.apache.velocity.runtime.parser.Token;
@@ -63,7 +64,7 @@
      * @see 
org.apache.velocity.runtime.parser.node.SimpleNode#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
     public Object init( InternalContextAdapter context, Object data)
-        throws Exception
+    throws TemplateInitException
     {
         Token t = getFirstToken();
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/Node.java
 Sun Nov  5 00:56:58 2006
@@ -19,16 +19,16 @@
  * under the License.    
  */
 
-import java.io.Writer;
 import java.io.IOException;
+import java.io.Writer;
 
 import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.ParserVisitor;
-import org.apache.velocity.runtime.parser.Token;
-
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.runtime.parser.ParserVisitor;
+import org.apache.velocity.runtime.parser.Token;
 
 /**
  *  This file describes the interface between the Velocity code
@@ -123,9 +123,9 @@
      * @param context
      * @param data
      * @return The init result.
-     * @throws Exception
+     * @throws TemplateInitException 
      */
-    public Object init( InternalContextAdapter context, Object data) throws 
Exception;
+    public Object init( InternalContextAdapter context, Object data) throws 
TemplateInitException;
 
     /**
      * @param context

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java?view=diff&rev=471381&r1=471380&r2=471381
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
 Sun Nov  5 00:56:58 2006
@@ -27,8 +27,8 @@
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.exception.ReferenceException;
 import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.ParserVisitor;
@@ -266,9 +266,10 @@
     }
 
     /**
+     * @throws TemplateInitException 
      * @see 
org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter,
 java.lang.Object)
      */
-    public Object init( InternalContextAdapter context, Object data) throws 
Exception
+    public Object init( InternalContextAdapter context, Object data) throws 
TemplateInitException
     {
         /*
          * hold onto the RuntimeServices
@@ -281,14 +282,7 @@
 
         for (i = 0; i < k; i++)
         {
-            try
-            {
-                jjtGetChild(i).init( context, data);
-            }
-            catch (ReferenceException re)
-            {
-                log.error(re);
-            }
+            jjtGetChild(i).init( context, data);
         }
 
         return data;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to