Tuesday, 15 September 2015

Python customized Exception class should allow to continue the program execution after it has been raised -



Python customized Exception class should allow to continue the program execution after it has been raised -

i wrote python programm has customized exception class called taexception , works fine. new requirement forces me extend functionaliy. if user sets specific flag (-n) on programme startup programme should not stop execution if taexception raised.

below see how tried implement it. in main() taexception.setnoabort() gets called if flag has been set. rest maybe self-explaining. point is: doesn't work. programme aborts when taexception raised. know why doesn't work, not know how can implement differently. please show me elegant way this?

class taexception(exception): _numofexception = 0 # how has exception been raised? _noabort = false # default abort test run if exception has been raised. def __init__(self, tr_inst, expr, msg): ''' parameters: tr_inst: testreport instance expr: look in error occured. msg: explanation error. ''' if tr_inst != none: if taexception._noabort true: # if abort test run on first exception beingness raised. taexception._numofexception += 1 # or else count exception , go on test run. # status of testreport set "failed" testreportgen. else: tr_inst.genreport([expr, msg], false) # generate testreport , exit. @staticmethod def setnoabort(): ''' sets taexception._noabort true. ''' taexception._noabort = true

when using parameter -n programme should not raise exception instead utilize warning (that won't stop program). can find more info on warning here : http://docs.python.org/2/library/warnings.html#module-warnings

python exception exception-handling python-2.7

No comments:

Post a Comment