Skip to content

Commit f141f5b

Browse files
pytorchbotpsiddh
andauthored
ExecutorchRuntimeException: Update the exception return type (#14498)
Co-authored-by: Siddartha Pothapragada <[email protected]>
1 parent 1b9442e commit f141f5b

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

extension/android/executorch_android/src/main/java/org/pytorch/executorch/ExecutorchRuntimeException.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class ExecutorchRuntimeException extends RuntimeException {
7575
}
7676

7777
static class ErrorHelper {
78+
private static final boolean ENABLE_READ_LOG_BUFFER = false;
7879
// Reusable StringBuilder instance
7980
private static final StringBuilder sb = new StringBuilder();
8081

@@ -92,14 +93,15 @@ static String formatMessage(int errorCode, String details) {
9293
.append("] ")
9394
.append(baseMessage)
9495
.append(": ")
95-
.append(details)
96-
.append("\nDetailed Logs:\n");
97-
98-
try {
99-
String[] logEntries = readLogBuffer(); // JNI call
100-
formatLogEntries(sb, logEntries);
101-
} catch (Exception e) {
102-
sb.append("Failed to retrieve detailed logs: ").append(e.getMessage());
96+
.append(details);
97+
if (ENABLE_READ_LOG_BUFFER) {
98+
try {
99+
sb.append("\nDetailed Logs:\n");
100+
String[] logEntries = readLogBuffer(); // JNI call
101+
formatLogEntries(sb, logEntries);
102+
} catch (Exception e) {
103+
sb.append("Failed to retrieve detailed logs: ").append(e.getMessage());
104+
}
103105
}
104106

105107
return sb.toString();

extension/android/jni/jni_helper.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ void throwExecutorchException(uint32_t errorCode, const std::string& details) {
1919
"org/pytorch/executorch/ExecutorchRuntimeException");
2020

2121
// Find the static factory method: makeExecutorchException(int, String)
22-
static auto makeExceptionMethod = exceptionClass->getStaticMethod<
23-
facebook::jni::local_ref<facebook::jni::JThrowable>(
24-
int, facebook::jni::alias_ref<facebook::jni::JString>)>(
25-
"makeExecutorchException",
26-
"(ILjava/lang/String;)Lorg/pytorch/executorch/ExecutorchRuntimeException;");
22+
static auto makeExceptionMethod =
23+
exceptionClass
24+
->getStaticMethod<facebook::jni::local_ref<facebook::jni::JThrowable>(
25+
int, facebook::jni::alias_ref<facebook::jni::JString>)>(
26+
"makeExecutorchException",
27+
"(ILjava/lang/String;)Ljava/lang/RuntimeException;");
2728

2829
auto jDetails = facebook::jni::make_jstring(details);
2930
// Call the factory method to create the exception object

0 commit comments

Comments
 (0)