7. Error handling Flashcards
1
Q
3 basic keywords
A
try:
except: just to except and skip the remaining code, can specify error type
finally: run anyway
2
Q
Traceback message
A
for i in range(10):
print(i)
if i == 5: raise Exception('this is my test msg')
program will end after raising exception
3
Q
assertion error
A
it’s a sanity check not to expect
4
Q
logging
A
import logging
logging.basicConfig(filename=’myProgramLog.txt’, level=logging.DEBUG, format=’%(asctime)s - %(levelname)s - %(message)s’)
#logging.disable(logging.CRITICAL) logging.debug('start of debug')