Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions extension/android/jni/jni_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ namespace executorch::jni_helper {
void throwExecutorchException(uint32_t errorCode, const std::string& details) {
// Get the current JNI environment
auto env = facebook::jni::Environment::current();
if (!env) {
return;
}

// Find the Java ExecutorchRuntimeException class
static auto exceptionClass = facebook::jni::findClassLocal(
"org/pytorch/executorch/ExecutorchRuntimeException");
// stable/global class ref — safe to cache
static const auto exceptionClass =
JExecutorchRuntimeException::javaClassStatic();

// Find the static factory method: makeExecutorchException(int, String)
static auto makeExceptionMethod =
Expand Down
7 changes: 7 additions & 0 deletions extension/android/jni/jni_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ namespace executorch::jni_helper {
*/
void throwExecutorchException(uint32_t errorCode, const std::string& details);

// Define the JavaClass wrapper
struct JExecutorchRuntimeException
: public facebook::jni::JavaClass<JExecutorchRuntimeException> {
static constexpr auto kJavaDescriptor =
"Lorg/pytorch/executorch/ExecutorchRuntimeException;";
};

} // namespace executorch::jni_helper
Loading