-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathu_exception.py
More file actions
178 lines (124 loc) · 3.66 KB
/
u_exception.py
File metadata and controls
178 lines (124 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/python
# -*- coding: utf-8 -*
# custom exception
__all__ = [
'UBaseException', 'DecoratorException', 'LoggerException',
'ResException', 'NoSuchProcess', 'AccessDenied', 'NetworkException',
'AsyncMsgError', 'ThreadTermException', 'LockFileError',
'NotImplementedYet', 'ConfigError'
]
class UBaseException(Exception):
"""
base Exception. All other Exceptions will inherit this.
"""
def __init__(self, msg):
self._msg = 'Base module Exception:' + str(msg)
def __str__(self):
return repr(self._msg)
# ## Decorator Exceptions ####
class DecoratorException(UBaseException):
"""
DecoratorException
"""
def __init__(self, msg):
super(self.__class__, self).__init__(msg)
# ## Log related exceptions ####
class LoggerException(UBaseException):
"""
Exception for logging, especially for u_log
"""
def __init__(self, msg):
super(self.__class__, self).__init__(msg)
# ## Resource related exceptions ####
class ResException(UBaseException):
"""
Resource related Exception
"""
def __init__(self, msg):
UBaseException.__init__(self, msg)
class NoSuchProcess(ResException):
"""
No such Process Exception
"""
def __init__(self, pid, str_process_name):
ResException.__init__(self, 'NoSuchProcess, pid %d, process name:%s' % (pid, str_process_name))
class AccessDenied(ResException):
"""
Resource Access Denied Exception
"""
def __init__(self, str_resource):
ResException.__init__(self, 'Resource access denied: %s' % str_resource
)
# ## Net related exceptions ####
class NetworkException(UBaseException):
"""
Network related Exception
"""
def __init__(self, msg=''):
UBaseException.__init__(self, msg)
class AsyncMsgError(NetworkException):
"""
async msg related Exception
"""
def __init__(self, msg=''):
NetworkException.__init__(self, msg)
# ## Shell related exceptions ####
class ShellException(UBaseException):
"""
Exception for shell
"""
def __init__(self, msg=''):
UBaseException.__init__(self, msg)
class IOException(UBaseException):
"""
IO related exceptions
"""
def __init__(self, msg=''):
UBaseException.__init__(self, msg)
class NoSuchFileOrDir(IOException):
"""
No such file or directory Exception
"""
def __init__(self, msg=''):
IOException.__init__(self, msg)
class ThreadTermException(UBaseException):
"""
Thread termination error
"""
def __init__(self, msg=''):
UBaseException.__init__(self, msg)
class NotInitialized(UBaseException):
"""
Not initialized yet
"""
def __init__(self, msg=''):
msg = 'Not initialized: %s' % msg
UBaseException.__init__(self, msg)
class LockFileError(UBaseException):
"""
LockFileError
"""
def __init__(self, msg=''):
msg = 'LockFileError: %s' % msg
UBaseException.__init__(self, msg)
class ExpectFailure(UBaseException):
"""
Expect failure for unittest
"""
def __init__(self, expect, got):
msg = 'expect failure, expect {0}, got {1}'.format(expect, got)
UBaseException.__init__(self, msg)
class NotImplementedYet(UBaseException):
"""
Not implemented yet
"""
def __init__(self, msg=''):
msg = 'The functionality is not implemented yet, {0}'.format(msg)
UBaseException.__init__(self, msg)
class ConfigError(UBaseException):
"""
ConfigError
"""
def __init__(self, msg=''):
msg = 'Configuration Error: {0}'.format(msg)
UBaseException.__init__(self, msg)