return raise exception python code example
Example 1: raise exception in python
raise Exception('I know Python!')
Example 2: except as Exception:
>>> def catch():
... try:
... asd()
... except Exception as e:
... print e.message, e.args
...
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
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')