From d966412ce1e3f60ab430716440a3413e87ceb2f6 2015-12-02 19:58:11 From: Miguel Valdez Date: 2015-12-02 19:58:11 Subject: [PATCH] SChainError class has been added --- diff --git a/schainpy/admin.py b/schainpy/admin.py index 2c504a9..ac5af84 100644 --- a/schainpy/admin.py +++ b/schainpy/admin.py @@ -5,7 +5,8 @@ notification class and a standard error handing class. $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $ """ -import os +import os, sys +import traceback import smtplib import ConfigParser import StringIO @@ -164,7 +165,7 @@ class SchainNotify: Exceptions: None. """ - + # note that the main configuration file is unavailable # the best that can be done is send an email to root using localhost mailserver confObj = SchainConfigure() @@ -272,8 +273,8 @@ class SchainNotify: print "***** Your system administrator has been notified *****" -class SchainError: - """SchainError is an exception class that is thrown for all known errors in using Schain Py lib. +class SchainError(Exception): + """SchainError is an exception class that is thrown for all known errors using Schain Py lib. Usage example: @@ -293,11 +294,12 @@ class SchainError: """ - def __init__(self, strInterpretation, exceptionList): + def __init__(self, strInterpretation, exceptionList=None): """ __init__ gathers the interpretation string along with all information from sys.exc_info(). - Inputs: strIntepretation - A string representing the programmer's interpretation of - why the exception occurred + Inputs: + strIntepretation - A string representing the programmer's interpretation of + why the exception occurred exceptionList - a list of strings completely describing the exception. Generated by traceback.format_exception(sys.exc_info()[0], @@ -311,6 +313,11 @@ class SchainError: Exceptions: None. """ + if not exceptionList: + exceptionList = traceback.format_exception(sys.exc_info()[0], + sys.exc_info()[1], + sys.exc_info()[2]) + self._strInterp = strInterpretation self._strExcList = exceptionList @@ -326,7 +333,7 @@ class SchainError: Exceptions: None. """ - excStr = 'The following Schain Python exception has occurred:\n' + excStr = '' excStr = excStr + self._strInterp + '\n\n' if self._strExcList != None: @@ -336,6 +343,7 @@ class SchainError: return excStr def __str__(self): + return(self.getExceptionStr()) @@ -361,7 +369,7 @@ class SchainError: return excStr if __name__ == '__main__': - + test = SchainNotify() test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify')