Changeset 4d76711 in sasmodels for sasmodels/exception.py
- Timestamp:
- Apr 5, 2016 10:33:44 AM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 3a45c2c, c4e7a5f
- Parents:
- cd0a808
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/exception.py
r823e620 r4d76711 2 2 Utility to add annotations to python exceptions. 3 3 """ 4 import sys 4 5 5 6 # Platform cruft: WindowsError is only defined on Windows. … … 13 14 pass 14 15 15 def annotate_exception( exc, msg):16 def annotate_exception(msg, exc=None): 16 17 """ 17 18 Add an annotation to the current exception, which can then be forwarded 18 to the caller using a bare "raise" statement to reraise the annotated 19 exception. 19 to the caller using a bare "raise" statement to raise the annotated 20 exception. If the exception *exc* is provided, then that exception is the 21 one that is annotated, otherwise *sys.exc_info* is used. 20 22 21 23 Example:: … … 24 26 >>> try: 25 27 ... print(D['hello']) 26 ... except Exception as exc:27 ... annotate_exception( exc,"while accessing 'D'")28 ... except: 29 ... annotate_exception("while accessing 'D'") 28 30 ... raise 29 31 Traceback (most recent call last): … … 31 33 KeyError: "hello while accessing 'D'" 32 34 """ 35 if not exc: 36 exc = sys.exc_info()[1] 37 33 38 # Can't extend WindowsError exceptions; instead raise a new exception. 34 39 # TODO: try to incorporate current stack trace in the raised exception
Note: See TracChangeset
for help on using the changeset viewer.