Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6754: Throw Error instead of System.exit()

Ryan Kurtze115cd1098d8
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java
index 090fd60d29..dd5a9aff76 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/headless/HeadlessAnalyzer.java
@@ -959,15 +959,17 @@ public class HeadlessAnalyzer {
}
}
}
+ catch (JythonStubException e) {
+ // We want to effectively exit with an error code, but this class may be used as a
+ // Ghidra library method in some scenarios, so System.exit(1) is too aggressive.
+ // Throwing an Error allows Ghidra to exit with an uncaught exception when run from
+ // the command line, but allows for the possibility of a library client to handle
+ // the problem in a way that better suits their application.
+ throw new Error(e);
+ }
catch (Exception exc) {
String logErrorMsg = "REPORT SCRIPT ERROR: " + scriptName + " : " + exc.getMessage();
- if (exc instanceof JythonStubException) {
- Msg.error(this, logErrorMsg);
- System.exit(1);
- }
- else {
- Msg.error(this, logErrorMsg, exc);
- }
+ Msg.error(this, logErrorMsg, exc);
}
return retOption;