This content has been marked as final.
Show 3 replies
-
1. Re: Throw undeclared checked exception inside try block?
adinn Oct 26, 2009 9:20 AM (in response to cbredesen)
I'm just starting to use Byteman to drive toward 100% test coverage on my project. Well done Andrew & team, this is a great help!
Team? Wanna join?
Am I going about this wrongly?
Well, assuming that your rule is like this:RULE blah de blah CLASS Foo METHOD foo AT INVOKE BAR IF TRUE DO THROW MyException()
then I am afraid so.
The problem is to do with what THROW means. The exception is thrown from the <em>trigger method</em> not the trigger point. THROW implies a short circuit of the whole method and throw an exception to the caller of foo(), just as RETURN means return to the caller of foo().
What you need to do is inject the THROW into bar() as follows:RULE blah de bar CLASS Foo METHOD bar AT ENTRY IF TRUE DO THROW MyException()
The only problem is that this clobbers <em>all</em> calls to bar(). So, how to get round this? Well, use a counter or flag or something to define the requisite logic in the condition of the rule on bar e.g.RULE blah de bar CLASS Foo METHOD bar AT ENTRY IF flagged($0) DO THROW MyException() RULE blah de foo CLASS Foo METHOD foo AT INVOKE bar IF TRUE DO flag($0) RULE blah de foo de doo CLASS Foo METHOD foo AT EXIT IF TRUE DO cl;ear($0)
The second and third rules, respectively, set and clear a flag value identified using $0, the target object for the call to foo. This makes sure the call to bar() only barfs when it is made inside a call to foo with the same recipient. -
2. Re: Throw undeclared checked exception inside try block?
cbredesen Oct 27, 2009 3:38 PM (in response to cbredesen)The exception is thrown from the trigger method not the trigger point.
Makes perfect sense now that I've re-read the doco. Cheers! -
3. Re: Throw undeclared checked exception inside try block?
adinn Oct 28, 2009 4:59 AM (in response to cbredesen)
Makes perfect sense now that I've re-read the doco. Cheers!
When all else fails . . .