summaryrefslogtreecommitdiffstats
path: root/libnativehelper
diff options
context:
space:
mode:
Diffstat (limited to 'libnativehelper')
-rw-r--r--libnativehelper/JNIHelp.c8
-rw-r--r--libnativehelper/include/nativehelper/JNIHelp.h17
2 files changed, 25 insertions, 0 deletions
diff --git a/libnativehelper/JNIHelp.c b/libnativehelper/JNIHelp.c
index e5abc0f5d..fb23a9e83 100644
--- a/libnativehelper/JNIHelp.c
+++ b/libnativehelper/JNIHelp.c
@@ -211,6 +211,14 @@ int jniThrowException(JNIEnv* env, const char* className, const char* msg)
return result;
}
+int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt,
+ va_list args)
+{
+ char msgBuf[512];
+ vsnprintf(msgBuf, sizeof(msgBuf), fmt, args);
+ return jniThrowException(env, className, msgBuf);
+}
+
/*
* Throw a java.lang.NullPointerException, with an optional message.
*/
diff --git a/libnativehelper/include/nativehelper/JNIHelp.h b/libnativehelper/include/nativehelper/JNIHelp.h
index 71ecf3844..1b5ff0c2e 100644
--- a/libnativehelper/include/nativehelper/JNIHelp.h
+++ b/libnativehelper/include/nativehelper/JNIHelp.h
@@ -118,6 +118,23 @@ inline int jniThrowException(JNIEnv* env, const char* className,
{
return jniThrowException(&env->functions, className, msg);
}
+
+extern "C" int jniThrowExceptionFmt(C_JNIEnv* env, const char* className,
+ const char* fmt, va_list args);
+
+/*
+ * Equivalent to jniThrowException but with a printf-like format string and
+ * variable-length argument list. This is only available in C++.
+ */
+inline int jniThrowExceptionFmt(JNIEnv* env, const char* className,
+ const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ return jniThrowExceptionFmt(&env->functions, className, fmt, args);
+ va_end(args);
+}
+
inline int jniThrowNullPointerException(JNIEnv* env, const char* msg)
{
return jniThrowNullPointerException(&env->functions, msg);