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" <[EMAIL PROTECTED]>
To: "Velocity Users List" <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to