hchin | 11 May 05:20 2007

identifying exception exits of methods

Hi,

   I'm currently using BCEL to identify the exit points of a method via
a return statement, and that has worked fine. What is missing now is
identifying exit points via exception (a throw statement in a catch
block)...does anyone have any experience doing this? I read about
exception handling code and it seems like one can identify the beginning
and end of the try block and the beginning of the catch block, but I
don't see how one can identify the end of a catch block (so that I can
iterate through instructions between the start of the catch block and
the end of the catch block to find a throw instruction). Any suggestions?

thanks,
Hui Nee
Arrin Daley | 11 May 06:08 2007
Picon
Picon

Re: identifying exception exits of methods

Hi Hui

Unless I'm missing something:

If you are only after the exit points to a method you don't really need 
to find the end of the catch block because the catch block after it has 
completed will fall back to the method in which it is contained and exit 
via the usual return, this is provided it does not throw another 
exception or cause another exception to be thrown.

I presume you also need to trace exit points from your method even if 
the exception is not caught or if a RunTimeException is caused? If so 
perhaps look at the interface org.apache.bcel.generic.ExceptionThrower 
as this interface is implemented by all bytecodes which could cause an 
exception to be thrown(including ATHROW and ReturnInstructions) so any 
instructions implementing ExceptionThrower would seem to mark the 
possible exits from a method.

Hope this helps

Bye Arrin

hchin <at> cse.unl.edu wrote:

>Hi,
>
>   I'm currently using BCEL to identify the exit points of a method via
>a return statement, and that has worked fine. What is missing now is
>identifying exit points via exception (a throw statement in a catch
>block)...does anyone have any experience doing this? I read about
(Continue reading)

hchin | 11 May 07:05 2007

Re: identifying exception exits of methods

Hi Arrin,

   What I'm looking for is actually the throw statement inside a catch
block, if the catch block does not contain a throw statement I will
just ignore it since (you're right) it will just return when it hits
the return statement as usual.

   I believe ExceptionThrower is implemented by many instructions; what
I'm doing is actually dynamically instrumenting some program to invoke
some other methods, so if I insert this extra code before every
implementation of ExceptionThrower, I'm afraid that I might end up
adding a lot of extra code...unless I'm missing something?

thanks again,
Hui Nee

> Hi Hui
>
> Unless I'm missing something:
>
> If you are only after the exit points to a method you don't really need
> to find the end of the catch block because the catch block after it has
> completed will fall back to the method in which it is contained and exit
> via the usual return, this is provided it does not throw another
> exception or cause another exception to be thrown.
>
> I presume you also need to trace exit points from your method even if
> the exception is not caught or if a RunTimeException is caused? If so
> perhaps look at the interface org.apache.bcel.generic.ExceptionThrower
> as this interface is implemented by all bytecodes which could cause an
(Continue reading)


Gmane