Skip to content

Instantly share code, notes, and snippets.

@maphew
Last active March 3, 2021 19:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maphew/e3a75c147cca98019cd8 to your computer and use it in GitHub Desktop.
Save maphew/e3a75c147cca98019cd8 to your computer and use it in GitHub Desktop.
import sys
debug = True
def exceptionHandler(exception_type, exception, traceback, debug_hook=sys.excepthook):
'''Print user friendly error messages normally, full traceback if DEBUG on.
Adapted from http://stackoverflow.com/questions/27674602/hide-traceback-unless-a-debug-flag-is-set
'''
if debug:
print '\n*** Error:'
# raise
debug_hook(exception_type, exception, traceback)
else:
print "\t%s: %s" % (exception_type.__name__, exception)
sys.excepthook = exceptionHandler
if __name__ == '__main__':
their_md5 = 'c38f03d2b7160f891fc36ec776ca4685'
my_md5 = 'c64e53bbb108a1c65e31eb4d1bb8e3b7'
if their_md5 != my_md5:
raise ValueError('md5 sum does not match!')
@maphew
Copy link
Author

maphew commented Dec 28, 2014

rev5: working implementation, as per Reut's example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment