native exception handling added

pull/13383/head
Andrey Pavlenko 14 years ago
parent d227079753
commit 4033d8324c
  1. 23
      modules/java/gen_java.py
  2. 15
      modules/java/src/java/CvException.java

@ -503,11 +503,14 @@ class JavaWrapperGenerator(object):
# jni_func(..) { return cv_func(..); }
ret = "return "
ext = ""
default = "return 0"
if fi.ctype == "void":
ret = ""
default = ""
elif fi.ctype == "string":
ret = "return env->NewStringUTF"
ext = ".c_str()"
default = 'return env->NewStringUTF("")'
elif fi.ctype in self.classes: # wrapped class:
ret = "return (jlong) new " + self.classes[fi.ctype].jname
@ -537,9 +540,22 @@ class JavaWrapperGenerator(object):
JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
($args)
{
//LOGD("$module::$fname()");
$j2cv
$ret( $cvname( $cvargs )$ext );
try {
//LOGD("$module::$fname()");
$j2cv
$ret( $cvname( $cvargs )$ext );
} catch(cv::Exception e) {
//LOGD("$module::$fname() catched cv::Exception: %s", e.what());
jclass je = env->FindClass("org/opencv/CvException");
if(!je) je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, e.what());
$default;
} catch (...) {
//LOGD("$module::$fname() catched ...");
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "Unknown exception in JNI code {$module::$fname()}");
$default;
}
}
@ -553,6 +569,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
cvname = cvname, \
cvargs = ", ".join([a for a in cvargs]), \
ext = ext, \
default = default
) )
# processing args with default values

@ -0,0 +1,15 @@
package org.opencv;
public class CvException extends Exception {
private static final long serialVersionUID = 1L;
public CvException(String msg) {
super(msg);
}
@Override
public String toString() {
return "CvException [" + super.toString() + "]";
}
}
Loading…
Cancel
Save