Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-342

try/catch not catching

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-4
    • 1.0-beta-10
    • class generator
    • None
    • xp

    Description

      Please see the testcase for multiple issues:
      1. the catch order sensitivity, seems only the first catch clause works

      2. Exceptions generated when calling a method are always wrapped in Groovy invoking exception. Users won't catch the situation by using the "original" java exception.

      3. This pops up only in a loose script:

      package bran.groovy
      try {
      1/0
      } catch (Exception ex) {
      println("worst")
      }

      The Exception was supposed to stand for the java.lang.Exception. Rather the runtime was looking for bran.package.Exception. Removing the package directive fix the problem.

      ---- TrycatchTest.groovy
      package bran.groovy
      import java.io.*
      import org.codehaus.groovy.runtime.*

      class TrycatchTest extends GroovyTestCase {

      void testMutipleCatches() {
      try

      { FileInputStream fis = new FileInputStream("c:\\++-~~~") println 'ok' }

      catch (InvokerInvocationException ie)

      { println("was here") }

      catch (FileNotFoundException e)

      { println("bad") } catch (Exception ex) { println("worst") }
      }

      // switch the order of the catches
      void testCatchesOrder() {
      try { FileInputStream fis = new FileInputStream("c:\\++-~~~") println 'ok' } catch (FileNotFoundException e) { println("bad") }

      catch (InvokerInvocationException ie)

      { // println("was here") }

      catch (Exception ex)

      { println("worst") }


      }
      // should probably throw the original exception
      void testCatchOriginal() {
      try

      { FileInputStream fis = new FileInputStream("c:\\++-~~~") println 'ok' }

      catch (FileNotFoundException e)

      { println("bad") }


      }

      void testException() {
      try

      { FileInputStream fis = new FileInputStream("c:\\++-~~~") println 'ok' }

      catch (Exception e)

      { println("got it") }


      }

      }

      Attachments

        1. TrycatchTest.groovy
          1 kB
          Bing Ran

        Activity

          People

            blackdrag Jochen Theodorou
            bingran Bing Ran
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: