Source code for schrodinger.analysis.visanalysis.vdexception

# ----------------------------------------------------------------------------
# Name:
#
#   vdexception.py
#
# Purpose:
#
#   This file contains the implementation of the VDException class. This class
#   provides a generic exception to be thrown by all VolumeData related
#   functionality.
#
# Copyright of:
#
#   Copyright Schrodinger, LLC. All rights reserved.
#
# Version:
#
#   Version         Author          Notes
#       1.0            DDR          Original Implementation
#
# Notes:
#
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Module imports.

import sys as sys

# End of module imports.
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Global constants.

# End of global constants.
# ----------------------------------------------------------------------------


# ----------------------------------------------------------------------------
# Class-definition:
#
#   VDException
#
# ----------------------------------------------------------------------------
[docs]class VDException(Exception): """ This is a simple Exception derived class used by the various VolumeData associated components to denote an error condition. """ # ------------------------------------------------------------------------
[docs] def __init__(self, msg, detail=None): """ This function creates a new VDException. The msg should describe the error condition. detail may contain a bit more information if that is appropriate. :param msg: The error message :type msg: `string` :param detail: Additional error detail :type detail: `string` """ # Self._func contains the name of the function where the exception # occurred. This uses a rather ugly bit of Python to get that # from the call stack. self._func = sys._getframe().f_back.f_code.co_name self._msg = msg self._detail = detail
# ------------------------------------------------------------------------ def __str__(self): """ This function converts this VDException to a meaningful error message that can be displayed by the Python interpreter. """ if self._detail is not None: return "%s : %s : %s" % (self._func, self._msg, self._detail) else: return "%s : %s" % (self._func, self._msg)
# End of class definition: VDException # ---------------------------------------------------------------------------- # End of file: vdexception.py # ----------------------------------------------------------------------------