Hi, 

I'm testing an application that uses the Velocity Template engine. I've
deliberately introduced some parse errors in to my .vm file to test
error handling in Template.merge(). The error is a $variable that isn't
present in the context. 

According to the API this should cause merge() to throw a
ParseErrorException, but it doesn't. I do get a log in velocity.log, but
no exception is thrown. 

I know Velocity bug 467 is tracking a similar issue (Velocity should
throw more Exceptions), but this case seems a little different, in so
much as the merge() method doesn't match the published API. 

Has anyone else seen this? Can anyone suggest an alternative way of
detecting parse errors from within the application? 

Thanks, 

Nicholas


Code extract:

      try
      {
        lTemplate = Velocity.getTemplate(lTemplateName);       
        lTemplate.merge(xiContext, lWriter);      
      }
      catch(ParseErrorException e)
      {
        throw new TemplateException(e.getMessage(), 
                                    "Failed to parse template for " + 
                                    xiTemplateType, 
                                    lTemplateName); 
      }

.vm file extract:
          
#set($Variable=$imnothere.notamethod())\r\n
$Variable things to do\r\n"

velocity.log extract:

41:57,352 - RHS of #set statement is null. Context will not be modified.
snstemplates/fax-urgent-body-en_US.vm [line 5, column 1]
2007-07-27 14:41:57,352 - Null reference [template
'snstemplates/fax-urgent-body-en_US.vm', line 6, column 1] : $Variable
cannot be resolved.

Reply via email to