Changeset 4d76711 in sasmodels for sasmodels/exception.py


Ignore:
Timestamp:
Apr 5, 2016 10:33:44 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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
Message:

adjust interface to sasview

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/exception.py

    r823e620 r4d76711  
    22Utility to add annotations to python exceptions. 
    33""" 
     4import sys 
    45 
    56# Platform cruft: WindowsError is only defined on Windows. 
     
    1314        pass 
    1415 
    15 def annotate_exception(exc, msg): 
     16def annotate_exception(msg, exc=None): 
    1617    """ 
    1718    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. 
    2022 
    2123    Example:: 
     
    2426        >>> try: 
    2527        ...    print(D['hello']) 
    26         ... except Exception as exc: 
    27         ...    annotate_exception(exc, "while accessing 'D'") 
     28        ... except: 
     29        ...    annotate_exception("while accessing 'D'") 
    2830        ...    raise 
    2931        Traceback (most recent call last): 
     
    3133        KeyError: "hello while accessing 'D'" 
    3234    """ 
     35    if not exc: 
     36        exc = sys.exc_info()[1] 
     37 
    3338    # Can't extend WindowsError exceptions; instead raise a new exception. 
    3439    # TODO: try to incorporate current stack trace in the raised exception 
Note: See TracChangeset for help on using the changeset viewer.