Re: Current template and line number
Daniel Dekany <[email protected]> Wed, 30 Jul 2014 23:28:50 +0200
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <[email protected]> |
Monday, July 28, 2014, 10:32:11 PM, Jaime Garza wrote: > Hi, > > I have a group of methods implementing TemplateMethodModelEx. In > them I need to raise my exception that will can display the template > name, the line and the column numbers. I know that these methods are > called from MethodCall. But I have no context to either the current > template name or the location of the element. > > At a minimum I would like to report the template name. > > Is that possible at all? > > This is for 2.3.19 TemplateException-s make a snapshot of the FTL(!) stack trace when they are instantiated, and store that snapshot. That's so even if you throw the exception in your code. And from the FTL stack trace the template and line and column can be extract. Question is, what public API-s you had for that in 2.3.19. 2.3.21 TemplateException has public API to get these information, so, since you are working with a patched FreeMarker anyway, you might as well backport those changes. If you keep the public API the same (any feedback on that is welcome!), then when you upgrade to 2.3.21+, you don't have to re-patch it again. (Another possibility is doing an Environment.getCurrentEnvironment().getCurrentNamespace().getTemplate(). Or at least I don't yet see in what situation that wouldn't work. But of course, that only gives you the template, not the line.) > Thanks > > Jaime -- Thanks, Daniel Dekany ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk