native exception handling added

This commit is contained in:
Andrey Pavlenko 2011-07-11 15:28:09 +00:00
parent d227079753
commit 4033d8324c
2 changed files with 35 additions and 3 deletions

View File

@ -503,11 +503,14 @@ class JavaWrapperGenerator(object):
# jni_func(..) { return cv_func(..); } # jni_func(..) { return cv_func(..); }
ret = "return " ret = "return "
ext = "" ext = ""
default = "return 0"
if fi.ctype == "void": if fi.ctype == "void":
ret = "" ret = ""
default = ""
elif fi.ctype == "string": elif fi.ctype == "string":
ret = "return env->NewStringUTF" ret = "return env->NewStringUTF"
ext = ".c_str()" ext = ".c_str()"
default = 'return env->NewStringUTF("")'
elif fi.ctype in self.classes: # wrapped class: elif fi.ctype in self.classes: # wrapped class:
ret = "return (jlong) new " + self.classes[fi.ctype].jname ret = "return (jlong) new " + self.classes[fi.ctype].jname
@ -537,9 +540,22 @@ class JavaWrapperGenerator(object):
JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
($args) ($args)
{ {
try {
//LOGD("$module::$fname()"); //LOGD("$module::$fname()");
$j2cv $j2cv
$ret( $cvname( $cvargs )$ext ); $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, \ cvname = cvname, \
cvargs = ", ".join([a for a in cvargs]), \ cvargs = ", ".join([a for a in cvargs]), \
ext = ext, \ ext = ext, \
default = default
) ) ) )
# processing args with default values # processing args with default values

View File

@ -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() + "]";
}
}