From: Keats <ke...@xa...> - 2004-03-09 22:33:18
|
----- Original Message ----- From: "Eric Ridge" <eb...@tc...> > > 3) #try directive > > <snip> > > > I remember Eric saying he did this a while ago, but then Brian talked > > him > > out of it. I'd like to hear the reasoning. I find it quite useful for > > validation and debugging. > > Reason being that nothing you do in a template should actually throw an > exception. And if it does, you want it reported. I see this as very > similar to the "On Error Resume Next" construct of VisualBasic... very > very bad. I've been mulling this over and I suppose you're right -- try/catch functionality isn't really needed. I was primarily thinking about using this for forms processing. This would allow me to do things like validate user-entered numbers and dates within a template (without relying on JavaScript). Of course I can write utilities to do this, e.g., $isInt() or $isDate(). The down-side is that *valid* input has to get parsed twice -- once to validate, and once to get the value. I suppose this is pretty negligible compared to the normal latency of a request. Another approach might be to change the casting functions to return objects instead of primitives. E.g., Integer toInt(Object o); instead of int toInt(Object o); Then I could just return null values instead of throwing exceptions: #set $age=$toInt($Form.age) #if (!$age){ Invalid age entered ($Form.age). } Since WM uses auto-boxing and unboxing of primitives anyway, this may actually be slightly more efficient. Hmmm ... Keats |