1/15
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
raising exceptions
stop running the code in this function and move the program execution to the except statement (try & except)
-raise keyword
-call to Exception() function
-a string w/ error message passed to Exception() function
getting the traceback as a string
error message, line # that caused error, sequence of function calls that led to error
what are assertions?
sanity check to make sure code isn’t doing something obviously wrong
“I assert that the condition holds true, and if not, there is a bug somewhere, so immediately stop the program”
assert format
assert ages[0] <= ages[-1]
logging
makes it easy to create a record of custom messages that you write
-messages describe when program execution has reached the logging function call & list any variable you have specified at that point in time
logging module format
import logging
logging.basicConfig(level=logging.DEBUG, format= ‘$(asctime)s - %(levelname)s - %(message)s’)
basicConfig() function
what you want to see, how you want those details displayed
logging.debug()
calls printed out not just string passed to them
-timestamp
DEBUG
don’t debug w/ what function?
print()
logging levels (lowest to highest)
DEBUG, INFO, WARNING, ERROR, CRITICAL
logging.debug()
used for small details; only care about these messages only when diagnosing problems
logging.info()
used to record info on general events in program or confirm that things are working at their point in program
logging.warning()
used to indicate a potential problem that doesn’t prevent the program from working but might do so in the future
logging.error()
used to record an error that caused the program to fail to do something
logging.critical()
used to indicate fatal error that has caused or is about to cause the program to stop running entirely