You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2017/02/09 04:26:41 UTC
[jira] [Commented] (GROOVY-8085) Exception in "finally" not caught
by outer "try"
[ https://issues.apache.org/jira/browse/GROOVY-8085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15858996#comment-15858996 ]
Daniel Sun commented on GROOVY-8085:
------------------------------------
{code}
// Test.groovy
try {
try {
true;
} finally {
1 / 0
}
} catch (Exception e) {
println "caughtt"
}
{code}
The above code can be compiled by groovyc and decompiled by jd as follows(1 / 0 appears many times...):
{code}
import groovy.lang.Binding;
import groovy.lang.Script;
import org.codehaus.groovy.runtime.BytecodeInterface8;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.callsite.CallSite;
public class Test
extends Script
{
public Test() {}
public Test(Binding context)
{
super(context);
}
public static void main(String... args)
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
arrayOfCallSite[0].call(InvokerHelper.class, Test.class, args);
}
public Object run()
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
if ((!BytecodeInterface8.isOrigInt()) || (__$stMC) || (BytecodeInterface8.disabledStandardMetaClass())) {
try
{
try
{
try
{
return Boolean.valueOf(true);
}
finally
{
arrayOfCallSite[3].call(Integer.valueOf(1), Integer.valueOf(0)); // 1 / 0
}
arrayOfCallSite[2].call(Integer.valueOf(1), Integer.valueOf(0)); // 1 / 0
}
catch (Exception e)
{
return arrayOfCallSite[4].callCurrent(this, "caughtt");
}
}
finally {}
} else {
try
{
try
{
try
{
return Boolean.valueOf(true);
}
finally
{
arrayOfCallSite[7].call(Integer.valueOf(1), Integer.valueOf(0)); // 1 / 0
}
arrayOfCallSite[6].call(Integer.valueOf(1), Integer.valueOf(0)); // 1 / 0
}
catch (Exception e)
{
return arrayOfCallSite[8].callCurrent(this, "caughtt");
}
}
finally {}
}
return null;
}
}
{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)