This is a set of tiny utilities you can use in your code or to study.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
505 B

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()