##// END OF EJS Templates
SChainError class has been added
Miguel Valdez -
r688:d966412ce1e3
parent child
Show More
@@ -5,7 +5,8 notification class and a standard error handing class.
5 5
6 6 $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $
7 7 """
8 import os
8 import os, sys
9 import traceback
9 10 import smtplib
10 11 import ConfigParser
11 12 import StringIO
@@ -164,7 +165,7 class SchainNotify:
164 165
165 166 Exceptions: None.
166 167 """
167
168
168 169 # note that the main configuration file is unavailable
169 170 # the best that can be done is send an email to root using localhost mailserver
170 171 confObj = SchainConfigure()
@@ -272,8 +273,8 class SchainNotify:
272 273
273 274 print "***** Your system administrator has been notified *****"
274 275
275 class SchainError:
276 """SchainError is an exception class that is thrown for all known errors in using Schain Py lib.
276 class SchainError(Exception):
277 """SchainError is an exception class that is thrown for all known errors using Schain Py lib.
277 278
278 279 Usage example:
279 280
@@ -293,11 +294,12 class SchainError:
293 294 """
294 295
295 296
296 def __init__(self, strInterpretation, exceptionList):
297 def __init__(self, strInterpretation, exceptionList=None):
297 298 """ __init__ gathers the interpretation string along with all information from sys.exc_info().
298 299
299 Inputs: strIntepretation - A string representing the programmer's interpretation of
300 why the exception occurred
300 Inputs:
301 strIntepretation - A string representing the programmer's interpretation of
302 why the exception occurred
301 303
302 304 exceptionList - a list of strings completely describing the exception.
303 305 Generated by traceback.format_exception(sys.exc_info()[0],
@@ -311,6 +313,11 class SchainError:
311 313 Exceptions: None.
312 314 """
313 315
316 if not exceptionList:
317 exceptionList = traceback.format_exception(sys.exc_info()[0],
318 sys.exc_info()[1],
319 sys.exc_info()[2])
320
314 321 self._strInterp = strInterpretation
315 322 self._strExcList = exceptionList
316 323
@@ -326,7 +333,7 class SchainError:
326 333
327 334 Exceptions: None.
328 335 """
329 excStr = 'The following Schain Python exception has occurred:\n'
336 excStr = ''
330 337 excStr = excStr + self._strInterp + '\n\n'
331 338
332 339 if self._strExcList != None:
@@ -336,6 +343,7 class SchainError:
336 343 return excStr
337 344
338 345 def __str__(self):
346
339 347 return(self.getExceptionStr())
340 348
341 349
@@ -361,7 +369,7 class SchainError:
361 369 return excStr
362 370
363 371 if __name__ == '__main__':
364
372
365 373 test = SchainNotify()
366 374
367 375 test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify')
General Comments 0
You need to be logged in to leave comments. Login now