[stringtemplate-interest] Fail on undefined property

Terence Parr parrt at cs.usfca.edu
Fri Jul 31 12:38:11 PDT 2009


On Jul 31, 2009, at 2:04 AM, Felix Dorner wrote:

> Hi,
>
> I'm accessing properties of a Properties object in my template. I  
> need to fail generation if a requested property isn't defined (but  
> StringTemplate happily inserts the empty String in such cases.

Yeah, that's it's basic mode but it can be inconsistent about what  
throws an exception.

> What I did is to subclass Properties so that it throws a runtime  
> exception upon its get() method on undefined properties. However, I  
> see that you also make use of containsKey(), so I'd need to override  
> that too, and I'm starting to feel that my approach is probably not  
> the right way to go. Isn't there an option that tells StringTemplate  
> to fail if an attribute is not defined?

Is this these C# version?

You could override StringTemplate an alter its get attribute method.
T


More information about the stringtemplate-interest mailing list