Return null if a record cannot be retrieved.
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / ResultSet.java
index 3d89bd7..fd55c1b 100644 (file)
@@ -1,5 +1,6 @@
 package org.yaz4j;
 
+import org.yaz4j.exception.ZoomException;
 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p;
 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p;
 import org.yaz4j.jni.yaz4jlib;
@@ -42,9 +43,15 @@ public class ResultSet {
       return this;
     }
 
-    public Record getRecord(int index) {
+    public Record getRecord(int index) throws ZoomException {
       SWIGTYPE_p_ZOOM_record_p record = 
         yaz4jlib.ZOOM_resultset_record(resultSet, index);
+      //may be out of range or unsupported syntax
+      if (record == null) {
+        return null;
+      }
+      int errorCode = yaz4jlib.ZOOM_record_error(record, null, null, null);
+      if (errorCode != 0) throw new ZoomException("Record excpetion, code " + errorCode);
       return new Record(record, this);
     }