You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Twan Kogels <tw...@twansoft.com> on 2004/02/19 13:36:38 UTC

MethodInvocationException line number?

Hello,

I have made a library of classes and functions which can be used by 
velocity. Sometimes my users call a function with a wrong parameter value, 
for example
===
$users.getUserById(12)
===

"$users" is a class with a "getUserById(int id)" function. This function 
loads the user from the database with ID = 12. When the user with id 12 
exists everything goes fine. But when there isn't a user with id of 12 a 
exception is thrown by getUserById(int id) function.

I figured out when a exception is thrown by a function called by a velocity 
template that a "MethodInvocationException" exception is thrown. So i catch 
this one:

=====
try{
...
Velocity.mergeTemplate("test2.vm", "UTF-8", context, sw );
...
}
catch(MethodInvocationException ex){
       displayError("\n------------------\n"
                          +ex.getReferenceName()+"."+ex.getMethodName()
                          +"\n------------------\n");
     }
=====

This displays a nice message when a exception occurs. The user which has 
written the velocity template can then fix the problem.

But sometimes a template calls many of the same functions, then a message 
like "a error was found with function users.getUserById" is not very 
usefull. The user has to check every getUserById function call.

Is there a way to report the line on which the MethodInvocationException 
was thrown? If that is possible is can make a clearer error message, for 
example: "a error was found with function users.getUserById on line x". The 
user can then goto line x in velocity template and fix the error.

Greetings,
Twan Kogels



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


Re: MethodInvocationException line number?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Feb 22, 2004, at 8:21 PM, Peter Romianowski wrote:

> Hi Geir,
>
>>> Again: shouldn't the Exceptions (where possible) provide a getRow() 
>>> and
>>> getColumn()-method (Along with getTemplate() and others)? It 
>>> wouldn't be
>>> that hard to implement / refactor and would improve the usability 
>>> (especially
>>> in user-interaction-scenarios).
>>>
>>> Parsing a text seems to be quite weird (even though it works for you 
>>> right
>>> now).
>> I was thinking along the same lines.  First, adding 
>> row/col/method/tmeplate etc to the exception, providing an base 
>> exception for others to use as well, and also to regularize the 
>> message so that it's something like :
>>    foo.vm (row, col) :
>> and start doing this for all the rest...
>
> Yep. That would be some minor refactoring, I guess. From your mail I 
> didn't
> get whether you (personally) want to work on it or not...

Definitely.  The whole logging thing is interesting.  I'm about to do 
some classloader stuff for something else, so it's time to see if we 
can get what we want for logging changes too


>
> BTW, how is the release plan evolving? When is there next (1.4) 
> release out?

It's coming out this week.  We are required to do a license change for 
anything released after March 1, so we'll get that out under v1.1 of 
the ASL, and then switch the codebase to v2.0

> The RC1 is out since 2003-10-10 according to the web site. If you need 
> any
> help... Would it be possible to post the release / development plan to 
> the
> website? Or into the wiki (with a reference from the website since 
> nobody can
> find it otherwise ;)?

That's a good idea.  IIRC you posted a note about the floating point, 
and quite honestly I didn't remember what we decided - need to go back 
to look at the list archive.


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: MethodInvocationException line number?

Posted by Peter Romianowski <an...@gmx.de>.
Hi Geir,

>> Again: shouldn't the Exceptions (where possible) provide a getRow() and
>> getColumn()-method (Along with getTemplate() and others)? It wouldn't be
>> that hard to implement / refactor and would improve the usability 
>> (especially
>> in user-interaction-scenarios).
>>
>> Parsing a text seems to be quite weird (even though it works for you 
>> right
>> now).
> 
> 
> I was thinking along the same lines.  First, adding 
> row/col/method/tmeplate etc to the exception, providing an base 
> exception for others to use as well, and also to regularize the message 
> so that it's something like :
> 
> 
>    foo.vm (row, col) :
> 
> and start doing this for all the rest...

Yep. That would be some minor refactoring, I guess. From your mail I didn't
get whether you (personally) want to work on it or not...

BTW, how is the release plan evolving? When is there next (1.4) release out?
The RC1 is out since 2003-10-10 according to the web site. If you need any
help... Would it be possible to post the release / development plan to the
website? Or into the wiki (with a reference from the website since nobody can
find it otherwise ;)?

Regards
Peter

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


RE: MethodInvocationException line number?

Posted by Tim Colson <tc...@cisco.com>.
>     foo.vm (row, col) :
howabout foo.vm (line, col)

rows are for spreadsheets where I come from. ;-)


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


Re: MethodInvocationException line number?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Feb 20, 2004, at 2:33 PM, Peter Romianowski wrote:

> Again: shouldn't the Exceptions (where possible) provide a getRow() and
> getColumn()-method (Along with getTemplate() and others)? It wouldn't 
> be
> that hard to implement / refactor and would improve the usability 
> (especially
> in user-interaction-scenarios).
>
> Parsing a text seems to be quite weird (even though it works for you 
> right
> now).

I was thinking along the same lines.  First, adding 
row/col/method/tmeplate etc to the exception, providing an base 
exception for others to use as well, and also to regularize the message 
so that it's something like :


    foo.vm (row, col) :

and start doing this for all the rest...

geir


>
> Regards
> Peter
>
> Twan Kogels wrote:
>
>> Hello Geir,
>> Thanks for the reply, it's good news that line numbering is enabled 
>> in the cvs versie. I've just downloaded it and it works perfect. I 
>> use a little function to extract the line and column information, 
>> maybe it also at any use for somebody else.
>> ===
>> public static Hashtable 
>> parseVelocityMethodInvocationExceptionMessage(String msg){
>>     //in template test2.vm at line=9 column=27 threw
>>     Pattern p=Pattern.compile("in template (.*?) at line=(\\d+) 
>> column=(\\d+) threw");
>>     Matcher m = p.matcher(msg);
>>     if(m.find()){
>>       Hashtable info=new Hashtable(3);
>>       String template=m.group(1);
>>       String line=m.group(2);
>>       String column=m.group(3);
>>       info.put("template", template);
>>       info.put("line", line);
>>       info.put("column", column);
>>       return info;
>>     }
>>     return null;
>>   }
>> ===
>> Greetings,
>> Twan
>> At 19:53 19-2-2004, you wrote:
>>> On Feb 19, 2004, at 7:36 AM, Twan Kogels wrote:
>>>
>>>> [SNIP]
>>>
>>>
>>>> This displays a nice message when a exception occurs. The user 
>>>> which has written the velocity template can then fix the problem.
>>>>
>>>> But sometimes a template calls many of the same functions, then a 
>>>> message like "a error was found with function users.getUserById" is 
>>>> not very usefull. The user has to check every getUserById function 
>>>> call.
>>>>
>>>> Is there a way to report the line on which the 
>>>> MethodInvocationException was thrown? If that is possible is can 
>>>> make a clearer error message, for example: "a error was found with 
>>>> function users.getUserById on line x". The user can then goto line 
>>>> x in velocity template and fix the error.
>>>
>>>
>>> Sure.  Done.  In CVS.  Build from CVS and see if it does what you 
>>> want
>>>
>>> geir
>>>
>>> -- 
>>> Geir Magnusson Jr                                   203-247-1713(m)
>>> geir@4quarters.com
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: MethodInvocationException line number?

Posted by Peter Romianowski <an...@gmx.de>.
Again: shouldn't the Exceptions (where possible) provide a getRow() and
getColumn()-method (Along with getTemplate() and others)? It wouldn't be
that hard to implement / refactor and would improve the usability (especially
in user-interaction-scenarios).

Parsing a text seems to be quite weird (even though it works for you right
now).

Regards
Peter

Twan Kogels wrote:

> Hello Geir,
> 
> Thanks for the reply, it's good news that line numbering is enabled in 
> the cvs versie. I've just downloaded it and it works perfect. I use a 
> little function to extract the line and column information, maybe it 
> also at any use for somebody else.
> ===
> public static Hashtable 
> parseVelocityMethodInvocationExceptionMessage(String msg){
>     //in template test2.vm at line=9 column=27 threw
>     Pattern p=Pattern.compile("in template (.*?) at line=(\\d+) 
> column=(\\d+) threw");
>     Matcher m = p.matcher(msg);
>     if(m.find()){
>       Hashtable info=new Hashtable(3);
>       String template=m.group(1);
>       String line=m.group(2);
>       String column=m.group(3);
>       info.put("template", template);
>       info.put("line", line);
>       info.put("column", column);
>       return info;
>     }
>     return null;
>   }
> ===
> 
> Greetings,
> Twan
> 
> At 19:53 19-2-2004, you wrote:
> 
>> On Feb 19, 2004, at 7:36 AM, Twan Kogels wrote:
>>
>>> [SNIP]
>>
>>
>>> This displays a nice message when a exception occurs. The user which 
>>> has written the velocity template can then fix the problem.
>>>
>>> But sometimes a template calls many of the same functions, then a 
>>> message like "a error was found with function users.getUserById" is 
>>> not very usefull. The user has to check every getUserById function call.
>>>
>>> Is there a way to report the line on which the 
>>> MethodInvocationException was thrown? If that is possible is can make 
>>> a clearer error message, for example: "a error was found with 
>>> function users.getUserById on line x". The user can then goto line x 
>>> in velocity template and fix the error.
>>
>>
>> Sure.  Done.  In CVS.  Build from CVS and see if it does what you want
>>
>> geir
>>
>> -- 
>> Geir Magnusson Jr                                   203-247-1713(m)
>> geir@4quarters.com
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 

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


Re: MethodInvocationException line number?

Posted by Twan Kogels <tw...@twansoft.com>.
Hello Geir,

Thanks for the reply, it's good news that line numbering is enabled in the 
cvs versie. I've just downloaded it and it works perfect. I use a little 
function to extract the line and column information, maybe it also at any 
use for somebody else.
===
public static Hashtable 
parseVelocityMethodInvocationExceptionMessage(String msg){
     //in template test2.vm at line=9 column=27 threw
     Pattern p=Pattern.compile("in template (.*?) at line=(\\d+) 
column=(\\d+) threw");
     Matcher m = p.matcher(msg);
     if(m.find()){
       Hashtable info=new Hashtable(3);
       String template=m.group(1);
       String line=m.group(2);
       String column=m.group(3);
       info.put("template", template);
       info.put("line", line);
       info.put("column", column);
       return info;
     }
     return null;
   }
===

Greetings,
Twan

At 19:53 19-2-2004, you wrote:

>On Feb 19, 2004, at 7:36 AM, Twan Kogels wrote:
>
>>[SNIP]
>
>>This displays a nice message when a exception occurs. The user which has 
>>written the velocity template can then fix the problem.
>>
>>But sometimes a template calls many of the same functions, then a message 
>>like "a error was found with function users.getUserById" is not very 
>>usefull. The user has to check every getUserById function call.
>>
>>Is there a way to report the line on which the MethodInvocationException 
>>was thrown? If that is possible is can make a clearer error message, for 
>>example: "a error was found with function users.getUserById on line x". 
>>The user can then goto line x in velocity template and fix the error.
>
>Sure.  Done.  In CVS.  Build from CVS and see if it does what you want
>
>geir
>
>--
>Geir Magnusson Jr                                   203-247-1713(m)
>geir@4quarters.com
>
>
>---------------------------------------------------------------------
>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: MethodInvocationException line number?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Feb 19, 2004, at 7:36 AM, Twan Kogels wrote:

> [SNIP]

> This displays a nice message when a exception occurs. The user which 
> has written the velocity template can then fix the problem.
>
> But sometimes a template calls many of the same functions, then a 
> message like "a error was found with function users.getUserById" is 
> not very usefull. The user has to check every getUserById function 
> call.
>
> Is there a way to report the line on which the 
> MethodInvocationException was thrown? If that is possible is can make 
> a clearer error message, for example: "a error was found with function 
> users.getUserById on line x". The user can then goto line x in 
> velocity template and fix the error.

Sure.  Done.  In CVS.  Build from CVS and see if it does what you want

geir

-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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