Some programmers use sys.exit
, others use SystemExit
.
- What is the difference?
- When do I need to use
SystemExit
orsys.exit
inside a function?
Example:
JavaScript
x
4
1
ref = osgeo.ogr.Open(reference)
2
if ref is None:
3
raise SystemExit('Unable to open %s' % reference)
4
or:
JavaScript
1
5
1
ref = osgeo.ogr.Open(reference)
2
if ref is None:
3
print('Unable to open %s' % reference)
4
sys.exit(-1)
5
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).