I\'ve got a single threaded app that should set the DOS errorlevel to something non-zero if there is a problem. Is it better to throw a RuntimeException, or to use System.ex
It depends how much information you want to report back to the script that starts your program. This can be very important if the script is designed to execute a chain of actions. https://shapeshed.com/unix-exit-codes/
Example: I developed a Java program that calls an external API, downloads the response and saves it to a file. Possible outcomes:
Now my script knows what went wrong, and it could take different actions based on the outcome.
Bottom line: like any good api, clearly define your input and output parameters and use System.exit.