Re: Exception Handling
Andrew Huntwork <[email protected]>
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <[email protected]> |
yeah, that looks generally fine. maybe you could post the code that
adds the exceptions and/or the "mangled" bytecode
Irving, Dave wrote:
> Hi,
>
> I've used BCEL a while ago to create **new** classes on the fly, but am
> getting stuck on something I've never had to do before: Inserting
> instructions to existing classes.
> Im trying to wrap each method in a class with a
> try/catch(NullPointerException).
> So this method:
>
> public int getInt() {
> return getIntFromSomewhere();
> }
>
> would become:
>
> public int getInt() {
> try {
> return getIntFromSomewhere();
> }
> catch(NullPointerException e) {
> // do something
> return 0;
> }
> }
>
> Im not having much luck at the moment - my current approach is this:
>
> 1) Use the methods InstructionList.getStart() to get the first instruction
> 2) Use InstructionList.getEnd() to get the last instruction
> 3) Add exception handling code (keeping an InstructionHandler to the first
> instruction in the handling code)
> 4) Add an appropriate return (using InstructionFactory.createNull ) if
> return type is not void
> 5) Add an exception handler to the method, using start and end obtained from
> 1/2 above, and the instruction handle obtained in 3 as the exception
> handling code handle
>
> Does this seem like a reasonable approach? Currently the methods produced
> seem to be completely mangled - so Im guessing Im way out on something -
> maybe one of my assumptions above.
> Any advice would be greatly appreciated!
>
> This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>