int jniThrowException(JNIEnv* env,
const char* className,
const char* msg)
int jniThrowNullPointerException(JNIEnv* env,
char* msg)
int jniThrowIOException(JNIEnv* env,
int errnum)
int jniThrowRuntimeException(JNIEnv* env,
const char* msg)
注意:虽然
const char* className
它是字符串,但是它是要传到中使用,所以它必须和某个类相对应的。
示例1
android_database_SQLiteQuery.cpp文件中的native_fill_window函数
static jint
native_fill_window(JNIEnv* env, jobject object, jobject javaWindow,
jint
startPos,
jint
offsetParam)
{
//略
if (statement == NULL) {
LOGE("Invalid statement in fillWindow()");
jniThrowException(env, "java/lang/IllegalStateException",
"Attempting to access a deactivated, closed, or empty cursor");
return
0;
}
// Only do the binding if there is a valid offsetParam. If no binding needs to be done
// offsetParam will be set to 0, an invliad value.
if
(offsetParam > 0) {
// Bind the offset parameter, telling the program which row to start with
err = sqlite3_bind_int(statement, offsetParam, startPos);
if
(err != SQLITE_OK) {
LOGE("Unable to bind offset position, offsetParam = %d", offsetParam);
jniThrowException(env, "java/lang/IllegalArgumentException",
sqlite3_errmsg(GET_HANDLE(env, object)));
return
0;
}
LOG_WINDOW("Bound to startPos %d", startPos);
} else {
LOG_WINDOW("Not binding to startPos %d", startPos);
}
// Get the native window
window = get_window_from_object(env, javaWindow);
if (!window) {
LOGE("Invalid CursorWindow");
jniThrowException(env, "java/lang/IllegalArgumentException","Bad CursorWindow");
return
0;
}
LOG_WINDOW("Window: numRows = %d, size = %d, freeSpace = %d", window->getNumRows(), window->size(), window->freeSpace());
numColumns = sqlite3_column_count(statement);
if (!window->setNumColumns(numColumns)) {
LOGE("Failed to change column count from %d to %d", window->getNumColumns(), numColumns);
jniThrowException(env, "java/lang/IllegalStateException", "numColumns mismatch");
return
0;
}
//略
}
示例2
android_util_EventLog.cpp中的android_util_EventLog_readEvents函数