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

Daniel Sun edited comment on GROOVY-8085 at 2/28/17 12:05 AM:
--------------------------------------------------------------

Beside John's suggestion, I provide you another(*Notice:* no finally block in 
the outer try-catch statement. If it contains a finally block and may throw 
exceptions, we will face same issue...):

{code}
try {
   def returnValue
   try {
      ...
      returnValue = ... 
   } finally {
      ... // some exception(e.g. exceptionX) is thrown
   }

   return returnValue;
} catch (Throwable t) { // the exceptionX can be caught
      ... 
}
{code}


was (Author: daniel_sun):
Beside John's suggestion, I provide you another(*Notice:* no finally block in 
the outer try-catch statement.):

{code}
try {
   def returnValue
   try {
      ...
      returnValue = ... 
   } finally {
      ... // some exception(e.g. exceptionX) is thrown
   }

   return returnValue;
} catch (Throwable t) { // the exceptionX can be caught
      ... 
}
{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
>          Components: Compiler
>    Affects Versions: 2.4.8
>         Environment: linux
>            Reporter: Craig Silverstein
>            Assignee: Daniel Sun
>            Priority: Critical
>             Fix For: 2.4.10
>
>
> 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)

Reply via email to