title: How to catch exception in groovy?
body: <p>In the below code:</p>
  
  <pre><code>def build(arg1, arg2, arg3, arg4, arg5){
  
      try{
  
          executeBuildCommand(commandString, component)
      }
      }catch(Exception e){
  
          print ' build() method raised exception'
          print "Error cause: ${e}"
          error('Build stage - failed')
      }
  }
  
  
  def executeBuildCommand(arg1, arg2){
  
      try{
          // BUILD_FULL = sh('build the code')
  
          if(BUILD_FULL == true){
              def data = new URL(${BUILD_URL}).getText()
          }        
      }catch(Exception e){
          throw e
      }   
  }
  </code></pre>
  
  <hr>
  
  <p>I understand that <code>"${BUILD_URL}"</code> interpolates in runtime</p>
  
  <p>But <code>catch</code> block in <code>build()</code> method, does not catch exception thrown on line(<code>def data = new URL(${BUILD_URL}).getText()</code>)</p>
  
  <p>instead I receive exception stack</p>
  
  <pre><code>java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, acceptGitLabMR, 
  addGitLabMRComment, addInteractivePromotion, ansiColor, archive, artifactoryDistributeBuild,... ]  or 
  globals [Artifactory, LastChanges, currentBuild, docker, env, params, pipeline, scm]
      at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:201)
      at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
  </code></pre>
  
  <hr>
  
  <p>How to handle exceptions?</p>