Return-Path: Delivered-To: apmail-jakarta-bcel-user-archive@www.apache.org Received: (qmail 24396 invoked from network); 4 Feb 2005 20:07:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Feb 2005 20:07:28 -0000 Received: (qmail 33877 invoked by uid 500); 4 Feb 2005 20:07:27 -0000 Delivered-To: apmail-jakarta-bcel-user-archive@jakarta.apache.org Received: (qmail 33849 invoked by uid 500); 4 Feb 2005 20:07:27 -0000 Mailing-List: contact bcel-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "BCEL Users List" Reply-To: "BCEL Users List" Delivered-To: mailing list bcel-user@jakarta.apache.org Received: (qmail 33833 invoked by uid 99); 4 Feb 2005 20:07:27 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,UPPERCASE_25_50 X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of rajendra.kumar.reddy.koduru@sap.com designates 155.56.68.170 as permitted sender) Received: from smtpde02.sap-ag.de (HELO smtpde02.sap-ag.de) (155.56.68.170) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 04 Feb 2005 12:07:27 -0800 Received: from sap-ag.de (smtpde02) by smtpde02.sap-ag.de (out) with ESMTP id VAA23607 for ; Fri, 4 Feb 2005 21:07:23 +0100 (MEZ) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Please help me regarding finally block Date: Fri, 4 Feb 2005 21:07:22 +0100 Message-ID: <73DFF891F8024B48AD56B594C4C5038A6BDACA@dewdfe23.wdf.sap.corp> Thread-Topic: Please help me regarding finally block Thread-Index: AcUK0Fbl7VqZQZTKSOqcCvwgKQCV5AAAaH8QAAfcA1A= From: "Koduru, Rajendra Kumar Reddy" To: "BCEL Users List" X-OriginalArrivalTime: 04 Feb 2005 20:07:23.0279 (UTC) FILETIME=[23BD21F0:01C50AF5] X-SAP: out X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi All,=20 =09 Currently i am planning to instrument each method of a class dynamically with system.out.println() statements. =09 as it is not possible to get it executed, due to the return statements which are available in middle of method,=20 As seen from many sources, implementing it with try and finally is a good idea. finally seems to be more complex to handle compared to catch (atleast to me). however i got the source from internet, i could not understand few things in the source, could some one please clarify me. i have directly put put my understandings and queries in the middle of code IN CAPS, [code is given below, of course not too big]. So please correct me and help me in this regard. Thank you Reddy public void instrumentMethod (ClassGen cg, MethodGen mg) { InstructionList il =3D mg.getInstructionList(); InstructionFactory ifact =3D new InstructionFactory(cg); InstructionHandle start =3D il.getStart(); InstructionHandle end =3D il.getEnd(); // IN THE FOLLOWING SNIPPET OF CODE, CALL TO SUBROUTINES ARE INSERTED AND ALL THE TARGETS OF RETURN INSTRUCTIONS ARE CHANGED Collection jsrs =3D new ArrayList(); for (Iterator i =3D il.iterator(); i.hasNext(); ) { InstructionHandle ih =3D (InstructionHandle)i.next(); if (ih.getInstruction() instanceof RETURN) { JSR jsr2 =3D new JSR(null); jsrs.add(jsr2); InstructionHandle n =3D il.insert(ih, jsr2); =09 il.redirectBranches(ih, n); } } // END OF ABOVE UNDERSTANDING. AM I CORRECT ?? =09 =09 InstructionHandle h1 =3D il.append(new ASTORE(0)); // AT THE CURRENT SITUATION, WHAT IS ON THE TOP OF STACK AND WHY IS IT STORED?? JSR jsr =3D new JSR(null); // WHY A SUBROUTINE CALL IS DONE HERE???=20 jsrs.add(jsr); il.append(jsr); InstructionHandle h2 =3D il.append(new ALOAD(0)); // REFLECTS THE ABOVE STORE OPERATION; SO WHAT IS ACTUALLY IN THIS NOW?? il.append(new ATHROW()); // I THINK IT IS TO RETHROW THE EXCEPTION IF AN EXCEPTION ARISES InstructionHandle handler =3D il.append(new ASTORE(1)); // STORES THE EXCEPTION VARIABLE // I WILL APPEND AN PRINTLN STATEMENT HERE=20 il.append(new RET(1)); // RETURNING FROM SUBROUTINE, BUT DOESNT THE INDEX OF RET START AT 0 for (JSR j : jsrs) { j.setTarget(handler); }=09 mg.addExceptionHandler(start, end, h1, null); // DOESNT THE EXCEPTION HANDLER START AT HANDLE handler(which is just 3 lines above in this code) il.setPositions(true); // IS THIS NECESSARY ?? } --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: bcel-user-help@jakarta.apache.org