import traceback class DBCError(Exception): pass class CheckError(DBCError): pass class PreError(DBCError): pass class PostError(DBCError): pass class SentinelError(DBCError): pass def check(test, msg, cls=CheckError): print(">>> ", msg) traceback.print_stack(limit=-1) if not test: raise cls(msg) def pre(test, msg): check(test, msg, PreError) def post(test, msg): check(test, msg, PostError) def sentinel(): traceback.print_stack(limit=-1) raise SentinelError()