File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Languages and the fly likes Catching undefined method in BeanShell Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Catching undefined method in BeanShell" Watch "Catching undefined method in BeanShell" New topic
Author

Catching undefined method in BeanShell

Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
Hi guys,

I'm playing around with bsh.

Need to know what's the exception thrown when a method does not exist and the invoke() is not implemented too. Is it just a generic EvalError or a subclass of it? ParseException or TargetError?

I would like to discriminate when the interface doesn't implement a method and control the message in my J2EE app: is there a way to know that from the exception thrown?

Cheers,

Renato


Renato Losio - www.arsenio.it - renatoweb@arsenio.it
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Wouldn't this be possible to test relatively easily?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
Yes, and looks like it's indeed throwing a EvalError exception.

But I am bit puzzled with the BeanShell documentation (I was looking for a subclass of EvalError). And I haven't found a way yet to discriminate an undefined method from any different evalError.

So the question is: how can I find if a method is implemented in the bsh file or not?

Ok, I can get the string description of error message but I wouldn't like to base my code on that...

Renato
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Renato Losio:
So the question is: how can I find if a method is implemented in the bsh file or not?

Off the cuff, would it be feasible to read in the source of the bsf file and do a semi-reliable regex match?

Originally posted by Renato Losio:
Ok, I can get the string description of error message but I wouldn't like to base my code on that...

Well, at least that would be a simple solution and with a sensible default, it shouldn't be the end of the world even if the message changes upon a version upgrade.
Renato Losio
Ranch Hand

Joined: Nov 23, 2005
Posts: 99
>Well, at least that would be a simple solution and with a sensible default

OK, I will go for that. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catching undefined method in BeanShell