You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/05/28 18:37:00 UTC

[jira] [Resolved] (GROOVY-5686) Exception catching: code compiles, but exception handling confusing.

     [ https://issues.apache.org/jira/browse/GROOVY-5686?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-5686.
---------------------------------
    Resolution: Information Provided

{code:groovy}
try {
  // ...
} catch (TypeName) {
  // ...
}
{code}

"TypeName" is actually a variable name, but looks like a type due to naming conventions.

> Exception catching: code compiles, but exception handling confusing.
> --------------------------------------------------------------------
>
>                 Key: GROOVY-5686
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5686
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 1.8.7
>         Environment: Linux
>            Reporter: Dr Josef Karthauser
>            Priority: Major
>
> Take a look at this code. When I fail to give an exception argument in a catch block that block appears to catch everything! Weird. What's going on?
> Joe
> {code}
>     @Test
>     void shouldCatchAnException_andDoes() {
>         try {
>             throw new ItemNotFoundException("")
>         } catch (ItemNotFoundException e) {
>             // ok
>             assert e
>         }
>     }
>     @Test
>     void shouldCatchAnException_wierdGroovySyntax_andDoes() {
>         try {
>             throw new ItemNotFoundException("")
>         } catch (ItemNotFoundException) {
>             // ok
>             assert true
>         }
>     }
>     @Test
>     void shouldNotCatchTheWrongException_andDoesnt() {
>         try {
>             throw new ItemNotFoundException("")
>         } catch (ValidationException e) {
>             assert false
>         } catch (Exception e) {
>             // ok
>         }
>     }
>     @Test
>     void shouldNotCatchTheWrongException_withWierdGroovySyntax_butDoes_whatIsGoingOk() {
>         try {
>             throw new ItemNotFoundException("")
>         } catch (ValidationException) {
>             assert false
>         } catch (Exception e) {
>             // ok
>         }
>     }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)