Source code for scuq.qexceptions
## \file qexceptions.py
# \brief This file contains a variety of exception definitions that are used
# by the quantities package.
# \author <a href="http://thomas.reidemeister.org/" target="_blank">
# Thomas Reidemeister</a>
## \namespace scuq::qexceptions
# \brief This namespace contains classes defining custom exceptions of
# this library.
## \defgroup qexceptions The Exceptions Module
#
# This module contains the classes to model, handle, and use special
# qexceptions that may occur while using of units and quantities.
# \author <a href="http://thomas.reidemeister.org/" target="_blank">
# Thomas Reidemeister</a>
# \addtogroup qexceptions
# @{
[docs]
class QuantitiesException(Exception):
"""General class for qexceptions of this module."""
[docs]
def __init__(self, *args):
"""Default constructor.
args: Arguments of this exception
"""
Exception.__init__(self, *args)
[docs]
class UnitExistsException(QuantitiesException):
"""Raised when a unit or dimension symbol is already registered."""
[docs]
def __init__(self, unit, *args):
"""Default constructor.
unit: The unit that raised this exception.
args: Additional arguments of this exception.
"""
QuantitiesException.__init__(self, *args)
self._unit = unit
[docs]
def __str__(self):
"""Returns a string describing this exception.
Returns:
A string that describes this exception.
"""
return QuantitiesException.__str__(self) + " :" + self._unit.__str__()
[docs]
class ConversionException(QuantitiesException):
"""General exception that is raised whenever a
unit conversion fails.
"""
[docs]
def __init__(self, unit, *args):
"""Default constructor
unit: Instance of a unit that raised the exception.
args: Additional arguments of this exception.
"""
QuantitiesException.__init__(self, *args)
self._unit = unit
[docs]
def __str__(self):
"""Returns a string describing this exception.
Returns:
A string that describes the exception.
"""
return QuantitiesException.__str__(self) + " :" + self._unit.__str__()
[docs]
class NotDimensionlessException(QuantitiesException):
"""Exception that is raised whenever a
a unit is not dimensionless where it has to be.
"""
[docs]
def __init__(self, unit, *args):
"""Default constructor
unit: Instance of a unit that raised the exception.
args: Additional arguments of this exception.
"""
QuantitiesException.__init__(self, *args)
self._unit = unit
[docs]
def __str__(self):
"""Returns a string describing this exception.
Returns:
A string that describes the exception.
"""
return QuantitiesException.__str__(self) + " :" + self._unit.__str__()
[docs]
class UnknownUnitException(QuantitiesException):
"""An exception that is raised whenever an unexpected unit was used."""
[docs]
def __init__(self, unit, *args):
"""The default constructor.
unit: An instance of a unit that is unknown.
args: Additional arguments of this exception.
"""
QuantitiesException.__init__(self, *args)
self._unit = unit
[docs]
def __str__(self):
"""Returns a string describing this exception.
Returns:
String that describes the exception.
"""
return QuantitiesException.__str__(self) + " :" + self._unit.__str__()
## @}