[stringtemplate-interest] inconsistency: return null or throw exception

Nate misc at n4te.com
Mon Nov 13 12:09:08 PST 2006


The method StringTemplateGroup#lookupTemplate(StringTemplate, String) 
throws an IllegalArgumentException the first time a template is not 
found. Subsequent requests for the same template do not throw the 
IllegalArgumentException and instead return null. What is the reason for 
this inconsistency? IMO, the method should either always through the 
exception OR it should always return null. Currently I have to write 
code like the following to handle if the template was not found.

-Nate

StringTemplate template = null;
try {
    template = templateGroup.getInstanceOf(templateName);
} catch (RuntimeException ignored) {
    // getInstanceOf throws an IllegalArgumentException only the first 
time a template is not found.
}
if (template == null) {
   // Handle template not found.
}



More information about the stringtemplate-interest mailing list