Python Error Handling
return to DevPythonBasic Usage
try:
raise Exception("Hello World")
except Exception, e:
print type(e), e
raise Exception("Hello World")
except Exception, e:
print type(e), e
Custom Exceptions
class CustomException(Exception):
def __init__(self, value):
self.parameter = value
def __str__(self):
return repr(self.parameter)
def __init__(self, value):
self.parameter = value
def __str__(self):
return repr(self.parameter)
Traceback
try:
something_that_raises_an_exception()
except Exception, e:
import traceback; traceback.print_exc()
#or: import traceback; trace = traceback.format_exc()
something_that_raises_an_exception()
except Exception, e:
import traceback; traceback.print_exc()
#or: import traceback; trace = traceback.format_exc()
[There are no comments on this page]