Ignore:
Timestamp:
Jun 9, 2010 11:05:15 AM (11 years ago)
Author:
braffert
Message:

Added java exceptions where applicable. Also added Library.getInt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/java/jRpUnits.cc

    r1727 r1753  
    2222  const char* nativeFromVal = env->GetStringUTFChars(javaFromVal, 0);
    2323  const char* nativeTo = env->GetStringUTFChars(javaTo, 0);
    24   std::string retStr = RpUnits::convert(nativeFromVal, nativeTo, (int)units);
     24  int err;
     25  jclass ex;
     26  std::string errorMsg;
     27
     28  // perform conversion
     29  std::string retStr = RpUnits::convert(nativeFromVal, nativeTo,
     30                                       (int)units, &err);
     31
     32  // raise a runtime exception on error
     33  if (err){
     34    ex = env->FindClass("java/lang/RuntimeException");
     35    if (ex){
     36      errorMsg = "Connot convert ";
     37      errorMsg += nativeFromVal;
     38      errorMsg += " to ";
     39      errorMsg += nativeTo;
     40      env->ThrowNew(ex, errorMsg.c_str());
     41    }
     42    env->DeleteLocalRef(ex);
     43  }
     44
    2545  env->ReleaseStringUTFChars(javaFromVal, nativeFromVal);
    2646  env->ReleaseStringUTFChars(javaTo, nativeTo);
     47
     48  // create new java string and return
    2749  return (env->NewStringUTF(retStr.c_str()));
    2850}
Note: See TracChangeset for help on using the changeset viewer.