groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-8085) Exception in "finally" not caught by outer "try"
Date Fri, 17 Feb 2017 17:21:41 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15867440#comment-15867440
] 

Daniel Sun edited comment on GROOVY-8085 at 2/17/17 5:21 PM:
-------------------------------------------------------------

My test code:
{code}
    public static void main(String[] args) {
        try { 
            try { 
                System.out.println("try!!!");
            } finally { 
                99 / 0 
            }
        } catch (Exception e) { 
            System.out.println("catch!!!"); 
        }
    }
{code}

*There are two exception tables to handle 0/1, one will print "catch!!!" but another will
throw the exception:*
{code}
TRYCATCHBLOCK L3 L5 L5 java/lang/Exception
...
TRYCATCHBLOCK L3 L5 L6 null
{code}

The related bytecodes are shown as follows:
{code}
  // access flags 0x1
  public run()Ljava/lang/Object;
    TRYCATCHBLOCK L0 L1 L2 null
    TRYCATCHBLOCK L3 L4 L2 null
    TRYCATCHBLOCK L0 L1 L5 java/lang/Exception            
    TRYCATCHBLOCK L3 L5 L5 java/lang/Exception
    TRYCATCHBLOCK L0 L1 L6 null
    TRYCATCHBLOCK L3 L5 L6 null
    TRYCATCHBLOCK L5 L7 L6 null
    TRYCATCHBLOCK L8 L9 L6 null
    TRYCATCHBLOCK L10 L11 L12 null
    TRYCATCHBLOCK L13 L14 L12 null
    TRYCATCHBLOCK L10 L11 L15 java/lang/Exception      
    TRYCATCHBLOCK L13 L15 L15 java/lang/Exception
    TRYCATCHBLOCK L10 L11 L16 null
    TRYCATCHBLOCK L13 L15 L16 null
    TRYCATCHBLOCK L15 L17 L16 null
    TRYCATCHBLOCK L18 L19 L16 null
   L20
    INVOKESTATIC script1487143002698.$getCallSiteArray ()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
    ASTORE 1
    INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8.isOrigInt ()Z
    IFEQ L0
    GETSTATIC script1487143002698.__$stMC : Z
    IFNE L0
    INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass
()Z
    IFNE L0
    GOTO L10
   L0
    LINENUMBER 4 L0
    ALOAD 1
    LDC 1
    AALOAD
    ALOAD 1
    LDC 2
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "try!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 2
    NOP
   L1
    LINENUMBER 6 L1
    ALOAD 1
    LDC 3
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
   L3
    ALOAD 2
    ARETURN
    GOTO L4
   L4
    ALOAD 1
    LDC 4
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
    GOTO L21
   L2
    ASTORE 3
    ALOAD 1
    LDC 5
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    ALOAD 3
    ATHROW
   L21
    GOTO L22
   L5
    ASTORE 4
   L23
    LINENUMBER 9 L23
    ALOAD 1
    LDC 6
    AALOAD
    ALOAD 1
    LDC 7
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "catch!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 5
    NOP
   L7
    NOP
   L8
    ALOAD 5
    ARETURN
    NOP
   L9
    GOTO L22
   L22
    NOP
    GOTO L24
   L6
    ASTORE 6
    ALOAD 6
    ATHROW
   L24
    GOTO L25
   L10
    LINENUMBER 4 L10
    ALOAD 1
    LDC 8
    AALOAD
    ALOAD 1
    LDC 9
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "try!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 7
    NOP
   L11
    LINENUMBER 6 L11
    ALOAD 1
    LDC 10
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
   L13
    ALOAD 7
    ARETURN
    GOTO L14
   L14
    ALOAD 1
    LDC 11
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
    GOTO L26
   L12
    ASTORE 8
    ALOAD 1
    LDC 12
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    ALOAD 8
    ATHROW
   L26
    GOTO L27
   L15
    ASTORE 9
   L28
    LINENUMBER 9 L28
    ALOAD 1
    LDC 13
    AALOAD
    ALOAD 1
    LDC 14
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "catch!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 10
    NOP
   L17
    NOP
   L18
    ALOAD 10
    ARETURN
    NOP
   L19
    GOTO L27
   L27
    NOP
    GOTO L25
   L16
    ASTORE 11
    ALOAD 11
    ATHROW
   L25
    ACONST_NULL
    ARETURN
    LOCALVARIABLE this Lscript1487143002698; L20 L25 0
    LOCALVARIABLE e Ljava/lang/Exception; L23 L9 4
    LOCALVARIABLE e Ljava/lang/Exception; L28 L19 9
    MAXSTACK = 3
    MAXLOCALS = 12

{code}


was (Author: daniel_sun):
My test code:
{code}
    public static void main(String[] args) {
        try { 
            try { 
                System.out.println("try!!!");
            } finally { 
                99 / 0 
            }
        } catch (Exception e) { 
            System.out.println("catch!!!"); 
        }
    }
{code}

The related bytecodes are shown as follows:
{code}
  // access flags 0x1
  public run()Ljava/lang/Object;
    TRYCATCHBLOCK L0 L1 L2 null
    TRYCATCHBLOCK L3 L4 L2 null
    TRYCATCHBLOCK L0 L1 L5 java/lang/Exception            !!! The exception handler does not
cover the whole try-finally statement !!!
    TRYCATCHBLOCK L3 L5 L5 java/lang/Exception
    TRYCATCHBLOCK L0 L1 L6 null
    TRYCATCHBLOCK L3 L5 L6 null
    TRYCATCHBLOCK L5 L7 L6 null
    TRYCATCHBLOCK L8 L9 L6 null
    TRYCATCHBLOCK L10 L11 L12 null
    TRYCATCHBLOCK L13 L14 L12 null
    TRYCATCHBLOCK L10 L11 L15 java/lang/Exception      !!! The exception handler does not
cover the whole try-finally statement !!!
    TRYCATCHBLOCK L13 L15 L15 java/lang/Exception
    TRYCATCHBLOCK L10 L11 L16 null
    TRYCATCHBLOCK L13 L15 L16 null
    TRYCATCHBLOCK L15 L17 L16 null
    TRYCATCHBLOCK L18 L19 L16 null
   L20
    INVOKESTATIC script1487143002698.$getCallSiteArray ()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
    ASTORE 1
    INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8.isOrigInt ()Z
    IFEQ L0
    GETSTATIC script1487143002698.__$stMC : Z
    IFNE L0
    INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass
()Z
    IFNE L0
    GOTO L10
   L0
    LINENUMBER 4 L0
    ALOAD 1
    LDC 1
    AALOAD
    ALOAD 1
    LDC 2
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "try!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 2
    NOP
   L1
    LINENUMBER 6 L1
    ALOAD 1
    LDC 3
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
   L3
    ALOAD 2
    ARETURN
    GOTO L4
   L4
    ALOAD 1
    LDC 4
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
    GOTO L21
   L2
    ASTORE 3
    ALOAD 1
    LDC 5
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    ALOAD 3
    ATHROW
   L21
    GOTO L22
   L5
    ASTORE 4
   L23
    LINENUMBER 9 L23
    ALOAD 1
    LDC 6
    AALOAD
    ALOAD 1
    LDC 7
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "catch!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 5
    NOP
   L7
    NOP
   L8
    ALOAD 5
    ARETURN
    NOP
   L9
    GOTO L22
   L22
    NOP
    GOTO L24
   L6
    ASTORE 6
    ALOAD 6
    ATHROW
   L24
    GOTO L25
   L10
    LINENUMBER 4 L10
    ALOAD 1
    LDC 8
    AALOAD
    ALOAD 1
    LDC 9
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "try!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 7
    NOP
   L11
    LINENUMBER 6 L11
    ALOAD 1
    LDC 10
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
   L13
    ALOAD 7
    ARETURN
    GOTO L14
   L14
    ALOAD 1
    LDC 11
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    NOP
    GOTO L26
   L12
    ASTORE 8
    ALOAD 1
    LDC 12
    AALOAD
    BIPUSH 99
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    POP
    ALOAD 8
    ATHROW
   L26
    GOTO L27
   L15
    ASTORE 9
   L28
    LINENUMBER 9 L28
    ALOAD 1
    LDC 13
    AALOAD
    ALOAD 1
    LDC 14
    AALOAD
    LDC Ljava/lang/System;.class
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty (Ljava/lang/Object;)Ljava/lang/Object;
    LDC "catch!!!"
    INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.call (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    ASTORE 10
    NOP
   L17
    NOP
   L18
    ALOAD 10
    ARETURN
    NOP
   L19
    GOTO L27
   L27
    NOP
    GOTO L25
   L16
    ASTORE 11
    ALOAD 11
    ATHROW
   L25
    ACONST_NULL
    ARETURN
    LOCALVARIABLE this Lscript1487143002698; L20 L25 0
    LOCALVARIABLE e Ljava/lang/Exception; L23 L9 4
    LOCALVARIABLE e Ljava/lang/Exception; L28 L19 9
    MAXSTACK = 3
    MAXLOCALS = 12

{code}

> Exception in "finally" not caught by outer "try"
> ------------------------------------------------
>
>                 Key: GROOVY-8085
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8085
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.8
>         Environment: linux
>            Reporter: Craig Silverstein
>
> I would expect the following code to print `caughtt`:
> ```
> groovy -e 'try { try { true; } finally { 1 / 0 } } catch (e) { println "caughtt" }'
> ```
> But instead, it prints:
> ```
> Caught: java.lang.ArithmeticException: Division by zero
> java.lang.ArithmeticException: Division by zero
>         at script_from_command_line.run(script_from_command_line:1)
> ```
> Why is the exception, thrown by the `finally`, not being caught by the outer try/catch?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message