exception_translator.py 689 B

123456789101112131415161718192021222324252627
  1. # Copyright David Abrahams 2004. Distributed under the Boost
  2. # Software License, Version 1.0. (See accompanying
  3. # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. '''
  5. >>> from exception_translator_ext import *
  6. >>> try:
  7. ... throw_error();
  8. ... except RuntimeError as x:
  9. ... print(x)
  10. ... else:
  11. ... print('Expected a RuntimeError!')
  12. !!!error!!!
  13. '''
  14. def run(args = None):
  15. import sys
  16. import doctest
  17. if args is not None:
  18. sys.argv = args
  19. return doctest.testmod(sys.modules.get(__name__))
  20. if __name__ == '__main__':
  21. print("running...")
  22. import sys
  23. status = run()[0]
  24. if (status == 0): print("Done.")
  25. sys.exit(status)