title: How to catch a groovy thrown exception within java?
body: <p>I am trying to extend some legacy code to make it more tolerant of network outages. I have some (legacy) groovy code which wraps up a call to a webservice (CallWebService) via wslite. Sometimes, this call throws either a wslite.http.HTTPClientException or a java.net.ConnectException exception (this has been determined by adding 
  <code>log.info("Exception " + ex.getClass().getName() + " throw");</code> 
  to my log4j logging)</p>
  
  <p>The code which calls this groovy code is in java and looks like the following:</p>
  
  <pre><code>public static String getDataFromWebService(String webServiceUrl, String referenceNumber) {
  try {       
      ReturnedData returnedData = new CallWebService(webServiceUrl, referenceNumber);
      return (String)returnedData.toXml();
  }
  catch (Exception ex) {
      log.info("Exception caught: class of exception is " + ex.getClass().getName());
      throw ex;
  }
  </code></pre>
  
  <p>What I want to do, is catch the thrown exception (wslite.http.HTTPClientException or java.net.ConnectException) and retry the call (as it's probably a glitch) once or twice. </p>
  
  <p>When I try and add</p>
  
  <pre><code>catch (java.net.ConnectException ex)
  </code></pre>
  
  <p>and build, the build fails with </p>
  
  <pre><code>exception ConnectException is never thrown in body of corresponding try statement
  </code></pre>
  
  <p>What should I do to be able to catch and react to the appropriate exceptions?</p>