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 Sat, 25 Feb 2017 17:31:44 GMT

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

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

*The issue can be decribled accurately as follows:*
If the inner try block contains return statement(no matter whether explicit return or not)
and the inner finally block throws exceptions, the outer try block can not catch it. e.g.
{code}
try {
   try {
      ...
      return ... // no matter whether explicit return or not
   } finally {
      ... // some exception(e.g. exceptionX) is thrown
   }
} catch (Throwable t) { // the exceptionX can not be caught
      ... 
}
{code}

If developers' test cases have not covered the senario for their system, which may give them
a *surprise* in the production environment.


was (Author: daniel_sun):
*The issue can be decribled accurately as follows:*
If the inner try block contains return statement(no matter whether explicit return or not)
and the inner finally block throws exceptions, the outer try block can not catch it. e.g.
{code}
try {
   try {
      ...
      return ... // no matter whether explicit return or not
   } finally {
      ... // exceptionX is thrown
   }
} catch (Throwable t) { // the exceptionX can not be catched
      ... 
}
{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
>            Assignee: Daniel Sun
>            Priority: Critical
>             Fix For: 2.5.0-beta-1
>
>
> 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