Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-45469

Missing Pipeline DSL step exception is not caught by try-catch

    XMLWordPrintable

Details

    Description

      For example:

       

      node {
        try {
          nonExistingStep()
        } catch (e) {
          echo "exception caught !!!"
        }
      }
      

      catch block is not executed.

      Exception "java.lang.NoSuchMethodError: No such DSL method 'nonExistingStep'" is thrown anyway and build is failed.

       

      Attachments

        Activity

          jglick Jesse Glick added a comment -

          This is known to work; I suspect Groovy treats an untyped catch clause as catching Exception, whereas this is an Error.

          jglick Jesse Glick added a comment - This is known to work ; I suspect Groovy treats an untyped catch clause as catching Exception , whereas this is an Error .
          jglick Jesse Glick added a comment -

          Indeed similar is reproducible from command-line groovy.

          jglick Jesse Glick added a comment - Indeed similar is reproducible from command-line groovy .

          Catching Throwable works fine:

          catch(Throwable t) {
              throw e
          }
          

           

          https://stackoverflow.com/questions/38283476/java-nosuchmethoderror-not-caught-by-exception

          trane9991 Taras Postument added a comment - Catching Throwable works fine: catch (Throwable t) { throw e }   https://stackoverflow.com/questions/38283476/java-nosuchmethoderror-not-caught-by-exception
          jglick Jesse Glick added a comment -

          Better to catch NoSuchMethodError specifically, so you do not accidentally ignore unrelated problems.

          jglick Jesse Glick added a comment - Better to catch NoSuchMethodError specifically, so you do not accidentally ignore unrelated problems.

          People

            Unassigned Unassigned
            abeben Adam Beben
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: