You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Claude Brisson <cl...@renegat.net> on 2004/11/25 04:07:17 UTC

Re: Detect ReferenceException

Hi.

On Thu, 2004-11-25 at 00:22, Matthew Keene wrote:
> I'd like to be able to detect ReferenceExceptions (and
> other errors) that happen during a merge operation. 
> At the moment they appear in the velocity.log, but I'd
> like to be able to display them to the user.  At the
> very least I'd like to be able to detect that they
> have occurred so that I can put up a message telling
> them to check the log for error details.  So far I've
> been unable to work out how to do this, can anybody
> give me any pointers ?

Some errors do throw up exceptions, others don't...

For the former (like parse errors), you only have to catch them in your
servlet, then you can display the error to the user.

For the latter, it's more difficult... Typically, they are null #sets
and invalid references.

For null #sets (i.e. when you try to set a reference to a right-hand
value that evaluates to null), there is a NullSetEventHandler but... you
can't do much from inside the event handler (which only real purpose is
to say if you want it to be loggued or not...), apart from... throw a
RuntimeException (ouch!) or dwell with ThreadLocal objects...

For invalid references that's easier : you can use a
ReferenceInsertionEventHandler and check for null values from here. If
you encounter null values, you can decide to return a bright red error
tag in html that'll appear in-place in the rendered page.

Last but not least, I must mention Will's patch
http://issues.apache.org/bugzilla/show_bug.cgi?id=28388
that allows one to declare event handlers from within
velocity.properties, among other things. I hope it will be included in
version 1.5.

Hope that'll help

Claude



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Detect ReferenceException

Posted by Matthew Keene <df...@yahoo.com.au>.
 --- Will Glass-Husain <wg...@forio.com> wrote: 
> Me, I'd just implement a custom logger that parses
> the log text and detect 
> reference exceptions that way.  It's not the most
> elegant solution, but it 
> should work.
> 

OK, thanks, I think I'll go with the custom logger,
although I agree it's kind of inelegant.  Is there any
reason behind the design decision of having some
exceptions not passed all the way to the caller ?  It
does seem like these sort of errors are something that
somebody should know about, and logging a message may
not be the only thing anybody wants to do with them.

> > On Thu, 2004-11-25 at 00:22, Matthew Keene wrote:
> >> I'd like to be able to detect ReferenceExceptions
> (and
> >> other errors) that happen during a merge
> operation.
> >> At the moment they appear in the velocity.log,
> but I'd
> >> like to be able to display them to the user. 

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Detect ReferenceException

Posted by Will Glass-Husain <wg...@forio.com>.
Me, I'd just implement a custom logger that parses the log text and detect 
reference exceptions that way.  It's not the most elegant solution, but it 
should work.

WILL

----- Original Message ----- 
From: "Claude Brisson" <cl...@renegat.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, November 24, 2004 7:07 PM
Subject: Re: Detect ReferenceException


> Hi.
>
> On Thu, 2004-11-25 at 00:22, Matthew Keene wrote:
>> I'd like to be able to detect ReferenceExceptions (and
>> other errors) that happen during a merge operation.
>> At the moment they appear in the velocity.log, but I'd
>> like to be able to display them to the user.  At the
>> very least I'd like to be able to detect that they
>> have occurred so that I can put up a message telling
>> them to check the log for error details.  So far I've
>> been unable to work out how to do this, can anybody
>> give me any pointers ?
>
> Some errors do throw up exceptions, others don't...
>
> For the former (like parse errors), you only have to catch them in your
> servlet, then you can display the error to the user.
>
> For the latter, it's more difficult... Typically, they are null #sets
> and invalid references.
>
> For null #sets (i.e. when you try to set a reference to a right-hand
> value that evaluates to null), there is a NullSetEventHandler but... you
> can't do much from inside the event handler (which only real purpose is
> to say if you want it to be loggued or not...), apart from... throw a
> RuntimeException (ouch!) or dwell with ThreadLocal objects...
>
> For invalid references that's easier : you can use a
> ReferenceInsertionEventHandler and check for null values from here. If
> you encounter null values, you can decide to return a bright red error
> tag in html that'll appear in-place in the rendered page.
>
> Last but not least, I must mention Will's patch
> http://issues.apache.org/bugzilla/show_bug.cgi?id=28388
> that allows one to declare event handlers from within
> velocity.properties, among other things. I hope it will be included in
> version 1.5.
>
> Hope that'll help
>
> Claude
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org