jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Huntwork <...@huntwork.net>
Subject Re: Problems with Try/Catch Blocks
Date Mon, 21 Feb 2005 15:59:41 GMT
Vincent Marquez wrote:
> method name = public static void main(String[] arg0)
>    getstatic java.lang.System.out Ljava/io/PrintStream;
>    ldc "test"
>    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
>    new java/util/ArrayList
>    dup
>    invokespecial java/util/ArrayList/<init>()V
>    astore_1
>    goto -> 20

is this right?
try {
>    astore_1
>    getstatic java.lang.System.out Ljava/io/PrintStream;
>    ldc "test test test"
>    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
} catch(...

is this offset 20?
>    return
> =======================================================

if i'm right then your problem is...

> 
> ===============  AFTER ==================================
> method name = public void <init>()
>    aload_0
>    invokespecial java/lang/Object/<init>()V
>    return
> method name = public static java.util.ArrayList getArrList()
>    new java/util/ArrayList
>    dup
>     invokestatic java/util/ArrayList/getArrList()Ljava/util/ArrayList; 
> LoadClassType = java.util.ArrayList
>    areturn
> method name = public static void main(String[] arg0)
>    getstatic java.lang.System.out Ljava/io/PrintStream;
>    ldc "test"
>    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
>    new java/util/ArrayList
>    dup

this dup ^.  It leaves an extra object on the stack that will be there 
when you get to 20 via the goto -> 20 below but not if you get there via 
the exception catch block.  the stack in an exception handler is always 
just the exception object.  everything on the stack at the instruction 
that threw the exception gets tossed.

>     invokestatic java/util/ArrayList/getArrList()Ljava/util/ArrayList; 
> LoadClassType = java.util.ArrayList
>    astore_1
>    goto -> 20
>    astore_1
>    getstatic java.lang.System.out Ljava/io/PrintStream;
>    ldc "test test test"
>    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
>    return
> ====================================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Mime
View raw message