Some programmers use sys.exit, others use SystemExit.
- What is the difference?
- When do I need to use
SystemExitorsys.exitinside a function?
Example:
ref = osgeo.ogr.Open(reference)
if ref is None:
raise SystemExit('Unable to open %s' % reference)
or:
ref = osgeo.ogr.Open(reference)
if ref is None:
print('Unable to open %s' % reference)
sys.exit(-1)
Advertisement
Answer
No practical difference, but there’s another difference in your example code – print goes to standard out, but the exception text goes to standard error (which is probably what you want).