Thanks for the patch. I haven't looked at it yet, but I have one comment to the described solution:
A system property that controls the behaviour sounds very reasonable when you start ij from the command line and run it in a separate process. When using the programmatic API (the ij.runScript() method), on the other hand, a system property might not work so well, as it affects the entire JVM, and one may have multiple applications running in the same JVM expecting different behaviour from ij. For such applications it might be better if we add a new ij command, for example called exitonerror, modelled after the localizeddisplay and elapsedtime commands. Then the scripts that wanted this behaviour could start by invoking "exitonerror on" without affecting other applications running ij.runScript() in the same JVM.
If we add such a command, it probably isn't necessary to add the system property, but we might still want to do that for convenience, I suppose. How do you think an ij command would work for the use case you're struggling with?