# 12. Annotate exceptions

## `sasmodels.exception`

Utility to add annotations to python exceptions.

exception sasmodels.exception.WindowsError

  Bases: `Exception`

  Fake WindowsException when not on Windows.

  add_note(note, /)

    Add a note to the exception

  args
  with_traceback(tb, /)

    Set self.__traceback__ to tb and return self.

sasmodels.exception.annotate_exception(msg, exc=None)

  Add an annotation to the current exception, which can then be forwarded to the caller using a bare “raise” statement to raise the annotated exception. If the exception exc is provided, then that exception is the one that is annotated, otherwise sys.exc_info is used.

  Example:

      >>> D = {}
      >>> try:
      ...    print(D['hello'])
      ... except:
      ...    annotate_exception("while accessing 'D'")
      ...    raise
      Traceback (most recent call last):
          ...
      KeyError: "hello while accessing 'D'"