You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Matthew Keene <df...@yahoo.com.au> on 2004/11/25 00:22:28 UTC

Detect ReferenceException

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 ?

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 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


Re: Detect ReferenceException

Posted by Claude Brisson <cl...@renegat.net>.
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 Shinobu Kawai <sh...@gmail.com>.
Hi Matthew,

> OK, at the risk of sounding dumb I'm not entirely sure
> how this helps.  The only thing that sounds close to
> me is the ReferenceInsertionEventHandler.  Is your
> idea to implement a referenceInsert handler and check
> every insertion event to see whether the object is
> null ?

I failed to notice Claude's reply, but it's stated quite clearly there.  :)

>  Are there any other conditions that might
> generate errors but not throw an exception ?

You'll have to search the source for every call to
RuntimeLogger#error(...) and so on for an answer to that.

>  I guess
> what I really wanted was some way of alerting the
> users to all of these "silent" errors  - ie exceptions
> that don't get thrown but that appear only in the log.

Who are the "users"?  How will the "silent" errors messages help them?
 These questions might lead you to another solution.  ;)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.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 Matthew Keene <df...@yahoo.com.au>.
 --- Shinobu Kawai <sh...@gmail.com> wrote: 
> 
> Hi Matthew,
> 
> > I'd like to be able to detect ReferenceExceptions
> (and
> > other errors) that happen during a merge
> operation. 

> You can't detect ReferenceException because it is
> never thrown, but I
> think EventCartridge will help do what you want.
>    
>
http://jakarta.apache.org/velocity/developer-guide.html#EventCartridge%20and%20Event%20Handlers
> 
OK, at the risk of sounding dumb I'm not entirely sure
how this helps.  The only thing that sounds close to
me is the ReferenceInsertionEventHandler.  Is your
idea to implement a referenceInsert handler and check
every insertion event to see whether the object is
null ?  Are there any other conditions that might
generate errors but not throw an exception ?  I guess
what I really wanted was some way of alerting the
users to all of these "silent" errors  - ie exceptions
that don't get thrown but that appear only in the log.

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 Shinobu Kawai <sh...@gmail.com>.
Hi Matthew,

> 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 ?

You can't detect ReferenceException because it is never thrown, but I
think EventCartridge will help do what you want.
    http://jakarta.apache.org/velocity/developer-guide.html#EventCartridge%20and%20Event%20Handlers

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


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