Exception Handling
raise error_name("message")
ERRORS:
NameError-undefined variable,mistype in variable/function name or name not enclosed in quotes
TypeError- related to data types problems [eg. str doesn't work on int]
ValueError-when a function gets wrong data type as input
ZeroDivisinError
AttributeError-using wrong methods or returning none/no return statement
KeyError-dict
IndexError
IOError-file not found
EOFError - end of file error
FileNotFoundError
IndentationError
SYNTAX:
try:
except error1:runs if try has error1
except error2:runs if try has error2
Multiple exceptions can be specified in a except block. Eg
except error1, error2 :
else:runs if no error1
finally:always run, even if try block has return or break in it
Python debugger module == pdb
command prompt-$python-mpdbmycode.py
pdb COMMANDS:
l(lsit)-shows current position
n(next)-next line excluding function
s(step)-next line including function
r(return)-steps to end of current executing function
c(continue)-executes code
q(quit) enter key/ctrl+d
?(help)
FUNCTIONS:
pdb.set_trace()-creates a breakpoint
pdb.post_mortem(traceback)-enter post-morten debugging of given traceback object
pdb.pm()-enter post-morten debugging of given traceback object found in sys.last_traceback
pdb.run(statement)
pdb.runeval(expression)
pdb.runcall(function[arguments])
Comments
Post a Comment
For any queries or suggestions
Comment Here