The code I am working on has a bunch of TRY
/CATCH
blocks in Template::Toolkit
templates. They look like this:
[% TRY; x = OBJ.method(data); CATCH; "<!-- error: $error -->"; END %]
This is bad from two perspectives. First, the error is being inserted into the HTML handed to the user, and second, the error is hard to find for the developers. In my opinion, all errors should be logged to the same error log. Right now I do that through the warn
function. I have changed the code above to be
[% TRY %]
[% x = OBJ.foo(data) %]
[% CATCH %]
[% RAWPERL %]
warn "error calling method foo on a bar object: " . $stash->get("error");
[% END %]
[% END %]
but this feels far too verbose for what should be a simple thing. Is there some better way I am ignorant of to do this?