[ 
https://issues.apache.org/jira/browse/FREEMARKER-48?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15941645#comment-15941645
 ] 

Daniel Dekany edited comment on FREEMARKER-48 at 3/25/17 8:27 AM:
------------------------------------------------------------------

As far as I see, the idea was that {{TemplateMethodModelEx.exec}} shouldn't 
throw anything but {{TemplateModelException}}. If other exception is thrown 
inside the implementation of {{exec}}, you are supposed to catch it and rethrow 
it wrapped into a {{TemplateModelException}}. Then it will automatically carry 
the FreeMarker-specific location information, because {{TemplateException}}-s 
can do that (plain exceptions can't).

Of course, while the Java language forces you to do the above for checked 
exceptions, it's easy to forget about the unchecked ones. So certainly it would 
have been better if FreeMarker catches exceptions that you haven't wrapped into 
{{TemplateModelException}}, and wraps them into {{TemplateModelException}} 
itself. Heck, maybe {{exec}} should have been allowed to throw any kind of 
checked {{Exception}}, and then we catch and wrap them. But now doing so is not 
backward compatible. Maybe we can add a configuration option to catch the 
unchecked exceptions though. (BTW, we have the same problem with {{foo[bar]}}.) 
We will see in 2.3.27.


was (Author: ddekany):
As far as I see, the idea was that `TemplateMethodModelEx.exec` shouldn't throw 
anything but `TemplateModelException`. If other exception is thrown inside the 
implementation of `exec`, you are supposed to catch it and rethrow it wrapped 
into a `TemplateModelException`. Then it will automatically carry the 
FreeMarker-specific location information, because `TemplateException`-s can do 
that (plain exceptions can't).

Of course, while the Java forces you to do the above for checked exceptions, 
it's easy to forget about the unchecked ones. So certainly it would have been 
better if FreeMarker catches exceptions that you haven't wrapped into 
`TemplateModelException`, and wraps them into `TemplateModelException` itself. 
Heck, maybe `exec` should have been allowed to throw any kind of checked 
`Exception`, and then we catch and wrap them. But now doing so is not backward 
compatible. Maybe we can add a configuration option to catch the unchecked 
exceptions though. (BTW, we have the same problem with `foo[bar]`.) We will see 
in 2.3.27.

> When custom fremarker method throws exception, it is impossible to find 
> line/row where called
> ---------------------------------------------------------------------------------------------
>
>                 Key: FREEMARKER-48
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-48
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.25-incubating
>         Environment: Any
>            Reporter: Vojtech Knyttl
>
> Consider this stacktrace:
> https://gist.github.com/knyttl/dba8f94b9736eb2751074c34dce7b467
> On line `DispatcherServlet.renderView(DispatcherServlet.java:308)` I have 
> started freemarker to render a template. During that process it uses custom 
> method (`HrefMethod.exec(HrefMethod.java:28)`), but this method threw an 
> exception. However Freemarker does not report a line/row of the template 
> where this method was called making it very hard for debug.
> I would be happy if `freemarker.core.MethodCall._eval(MethodCall.java:65)` 
> had some try-catch blcok, that in case of an exception would add 
> lines/rows/details of the element that caused the exception.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to