I'm a little confused with the difference between these two approaches and could use some clarification. I have a stand alone python script in which all my geo-processes are enclosed in try/except blocks which is my standard operating procedure. However, in this particular script, if any exceptions are tossed, I want the script to abort. It will be run as a scheduled task.
sys — System-specific parameters and functions — Python 3.8.1 documentation mentions:
sys.exit([arg])https://docs.python.org/3/library/sys.html#sys.exit
Exit from Python. This is implemented by raising the <SPAN class="">SystemExit</SPAN> exception, so cleanup actions specified by finally clauses of <SPAN class="">try</SPAN> statements are honored, and it is possible to intercept the exit attempt at an outer level....
...
Since <SPAN class="">exit()</SPAN> ultimately “only” raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted.
If I try to use sys.exit in a console I get scolded with:
sys<SPAN class="punctuation token">.</SPAN>exit<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
An exception has occurred<SPAN class="punctuation token">,</SPAN> use <SPAN class="operator token">%</SPAN>tb to see the full traceback<SPAN class="punctuation token">.</SPAN>
SystemExit
C<SPAN class="punctuation token">:</SPAN>\EnvClones\arcgispro<SPAN class="operator token">-</SPAN>py3<SPAN class="operator token">-</SPAN>clone243\lib\site<SPAN class="operator token">-</SPAN>packages\IPython\core\interactiveshell<SPAN class="punctuation token">.</SPAN>py<SPAN class="punctuation token">:</SPAN><SPAN class="number token">3327</SPAN><SPAN class="punctuation token">:</SPAN> UserWarning<SPAN class="punctuation token">:</SPAN> To exit<SPAN class="punctuation token">:</SPAN> use <SPAN class="string token">'exit'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'quit'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">or</SPAN> Ctrl<SPAN class="operator token">-</SPAN>D<SPAN class="punctuation token">.</SPAN>
warn<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"To exit: use 'exit', 'quit', or Ctrl-D."</SPAN><SPAN class="punctuation token">,</SPAN> stacklevel<SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
So using exit() is the clear favorite there. Is sys.exit() preferred in a stand alone script?