"""Exception classes.

Robert A McDougal, 2011
"""

class SNNetError(Exception):
    """Parent class of all SNNet Errors."""
    
    def __repr__(self):
        return self.msg

    def __str__(self):
        return self.__repr__()

class SyntaxError(SNNetError):
    """Raised when unable to parse the input.
    
    Attributes:
        content -- the unparsable content
        message -- additional information, if any
    """
    
    def __init__(self, content, message=''):
        self.content = str(content)
        self.msg = str(message)
    
    def __repr__(self):
        if self.msg:
            return self.msg + ': ' + self.content
        return self.content
        

class CompareError(SNNetError):
    """Raised when attempting to compare NeuronGroups from different simulation.
    
    Attributes:
        message -- additional information, if any
    """
    
    def __init__(self, message=''):
        self.msg = str(message)

        
        
class SimulationFailedError(SNNetError):
    """Raised when simulation was unable to complete.
    
    Attributes:
        t -- time of failure (or None if unknown)
        message -- additional information, if any
    """
    
    def __init__(self, t=None, message=''):
        self.t = t
        self.msg = str(message)

    def __repr__(self):
        if self.t is not None:
            return ('t = %g: ' % self.t) + self.msg
        else:
            return self.msg

