[6320] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | """ |
---|
| 3 | ------------------------------------------------------------------------------ |
---|
| 4 | Mango 802.11 Reference Design Experiments Framework - Exceptions |
---|
| 5 | ------------------------------------------------------------------------------ |
---|
| 6 | License: Copyright 2019 Mango Communications, Inc. All rights reserved. |
---|
| 7 | Use and distribution subject to terms in LICENSE.txt |
---|
| 8 | ------------------------------------------------------------------------------ |
---|
| 9 | |
---|
| 10 | This module provides class definitions for exceptions. |
---|
| 11 | |
---|
| 12 | Functions (see below for more information): |
---|
| 13 | ConfigError() |
---|
| 14 | ParameterError() |
---|
| 15 | NodeError() |
---|
| 16 | TransportError() |
---|
| 17 | |
---|
| 18 | """ |
---|
| 19 | |
---|
| 20 | __all__ = ['ConfigError', 'ParameterError', 'NodeError', 'TransportError'] |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | # ----------------------------------------------------------------------------- |
---|
| 24 | # Exception base class |
---|
| 25 | # ----------------------------------------------------------------------------- |
---|
| 26 | |
---|
| 27 | class Error(Exception): |
---|
| 28 | """Base class for exceptions.""" |
---|
| 29 | pass |
---|
| 30 | |
---|
| 31 | # End Class |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | # ----------------------------------------------------------------------------- |
---|
| 35 | # Types of exceptions |
---|
| 36 | # ----------------------------------------------------------------------------- |
---|
| 37 | |
---|
| 38 | class ConfigError(Error): |
---|
| 39 | """Exception for configuration file errors. |
---|
| 40 | |
---|
| 41 | Attributes: |
---|
| 42 | message -- explanation message of the error |
---|
| 43 | """ |
---|
| 44 | def __init__(self, message): |
---|
| 45 | self.message = message |
---|
| 46 | |
---|
| 47 | def __str__(self): |
---|
| 48 | msg = "Config Error:" |
---|
| 49 | msg += " {0} \n".format(self.message) |
---|
| 50 | return msg |
---|
| 51 | |
---|
| 52 | # End Class |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | class ParameterError(Error): |
---|
| 56 | """Exception for parameter errors. |
---|
| 57 | |
---|
| 58 | Attributes: |
---|
| 59 | name -- name of the parameter |
---|
| 60 | message -- explanation message of the error |
---|
| 61 | """ |
---|
| 62 | def __init__(self, parameter, message): |
---|
| 63 | self.parameter = parameter |
---|
| 64 | self.message = message |
---|
| 65 | |
---|
| 66 | def __str__(self): |
---|
| 67 | msg = "" |
---|
| 68 | if self.parameter is not None: |
---|
| 69 | msg += "Parameter {0} \n".format(self.parameter) |
---|
| 70 | msg += " Error: {0} \n".format(self.message) |
---|
| 71 | return msg |
---|
| 72 | |
---|
| 73 | # End Class |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | class NodeError(Error): |
---|
| 77 | """Exception for nodes. |
---|
| 78 | |
---|
| 79 | Attributes: |
---|
| 80 | node -- node in which the error occurred. |
---|
| 81 | message -- explanation message of the error |
---|
| 82 | """ |
---|
| 83 | def __init__(self, node, message): |
---|
| 84 | self.node = node |
---|
| 85 | self.message = message |
---|
| 86 | |
---|
| 87 | def __str__(self): |
---|
| 88 | msg = "" |
---|
| 89 | if self.node is not None: |
---|
| 90 | msg += "{0} \n ".format(self.node.description) |
---|
| 91 | msg += "Error: {0} \n".format(self.message) |
---|
| 92 | return msg |
---|
| 93 | |
---|
| 94 | # End Class |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | class TransportError(Error): |
---|
| 98 | """Exception for transports. |
---|
| 99 | |
---|
| 100 | Attributes: |
---|
| 101 | transport -- transport in which the error occurred. |
---|
| 102 | message -- explanation message of the error |
---|
| 103 | """ |
---|
| 104 | |
---|
| 105 | def __init__(self, transport, message): |
---|
| 106 | self.transport = transport |
---|
| 107 | self.message = message |
---|
| 108 | |
---|
| 109 | def __str__(self): |
---|
| 110 | msg = "" |
---|
| 111 | if self.transport is not None: |
---|
| 112 | msg += "{0} \n".format(self.transport) |
---|
| 113 | msg += " Error: {0} \n".format(self.message) |
---|
| 114 | return msg |
---|
| 115 | |
---|
| 116 | # End Class |
---|
| 117 | |
---|