title: Groovy - handling exception - how to get Oracle error code
body: <p>I'm running a Groovy script in jMeter test plan like:</p>
  
  <pre><code>import groovy.sql.*;
  import java.sql.*;
  import oracle.jdbc.driver.OracleTypes;
  
  def url = vars['url']
  def user = vars['user']
  def password = vars['password']
  def driver = vars['driver']
  def sql = Sql.newInstance(url, user, password, driver)
  
  try{
      def result = sql.call("{? = call MY_FUNCTION(?,?)}", [Sql.NUMERIC, vars.get('MY_VAR'), 'MY_PARAM']);
  } catch (Exception ex) {
  
      log.error "getMsg: " + ex.getMessage(); 
  }
  
  finally{
      sql.close();
  }
  </code></pre>
  
  <p>which, on exception, returns whole Oracle error message:</p>
  
  <blockquote>
    <p>ORA-00001: unique constraint (constraint_name) violated... blah blah</p>
  </blockquote>
  
  <p>How could I get only the Oracle specific error code number, ex. 'ORA-00001' or '00001' or '1' (preferably not using regex or substring)?</p>
  
  <p>I tried using <a href="https://docs.oracle.com/en/database/oracle/oracle-database/18/jajdb/oracle/jdbc/OracleDatabaseException.html" rel="nofollow noreferrer">OracleDatabaseException</a> class but Groovy doesn't seem to handle it.</p>