python raise error and exit code example
Example 1: raise exception in python
raise Exception('I know Python!')
Example 2: python raise exception
>>> raise NameError('HiThere')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: HiThere
Example 3: python raise error exit
sys.exit('My error message')
print >>sys.stderr, "fatal error"
print("fatal error", file=sys.stderr)
raise SystemExit('error in code want to exit')
try:
raise SystemExit('error in code want to exit')
except:
print("program is still open")
Example 4: python: raise error
class MyError(TypeError):
pass
raise MyError('An error happened')