Re: How to stop (w/o exception)
"Jonathan Revusky" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Feb 26, 2008 at 6:48 PM, Newman, John W <[email protected]> wrote: > Instead of the macro I'd just put it in an if statement. Maybe I can try/catch stop exception in my servlet, but I may not always want to catch that. There should be a [#abort /] directive or something to do that. Well, one possibility is that you use [#stop "graceful"] when you intend for the exception to be ignored. And then in the java code, you could: try { .... template.process(dataModel,out); ... } catch (StopException stop) { if !("graceful".equals(stop.getMessage()) throw stop; } so you rethrow the exception unless the detail string associated with it is "graceful". In any case, Attila's suggestion of using a macro in conjunction with #return also works internally by throwing an exception except that it gets caught , so it unwinds to the point where the macro was called. You know, again, AFAICS, the only way to jump out of an arbitrarilly nested structure is by throwing an exception. > > > > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On Behalf Of Attila Szegedi > Sent: Tuesday, February 26, 2008 12:44 PM > To: FreeMarker-user > Subject: Re: [FreeMarker-user] How to stop (w/o exception) > > You could enclose your template body in a: > > [#macro actuallyRenderThePage] > ... > [/#macro] > [@actuallyRenderThePage/] > > and then use [#return] from within the macro body. Of course, that > doesn't address more complex situations, as stopping gracefully from > several levels of macros or includes. In these cases [#stop/] is the > only reliable mechanism -- you'll just have to catch and ignore it at > your point of Template.process() invocation... > > Attila. > > On 2008.02.26., at 17:44, Newman, John W wrote: > > > Hi, > > > > I tried searching but sourceforge is down... I'm sure this has been > > discussed before. > > > > > > We have the [#stop /] directive which throws an exception. Is there > > a way to stop processing gracefully? > > > > > > [#if somethingBad] > > [#stopGracefully /] > > [/#if] > > > > Sure I could do > > > > [#if ! somethingBad] > > Everything here > > [/#if] > > > > But I'm pretty sure there is a break or stop thing that should work > > here. Just wondering, thanks. > > > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/