I'm trying to write a class which can handle errors raised throughout my application. This is so I can change the format of the error messages in one class.
class ErrorMessage(Exception):
def __init__(self, error, classname):
self.error = error
self.classname = classname
self.errormsg = "scriptname.py, {0}, error={1}".format(self.classname, self.error)
print self.errormsg
class LoadFiles():
try:
something-bad-causes-error
except Exception,e:
raise ErrorMessage(e, "LoadFiles")
At the moment my script printers the custom error, however it continues to print the complete traceback before exiting on this line "raise ErrorMessage(e, "LoadFiles")"
scriptname.py, LoadFiles, error= LoadFiles instance has no attribute 'config'
Traceback (most recent call last):
File "run.py", line 95, in <module>
scriptname().main()
File "run.py", line 54, in main
self.loadfiles()
File "run.py", line 45, in loadfiles
"removed" = LoadFiles(self.commands).load_files()
File "dir/core/loadfiles.py", line 55, in load_files
raise ErrorMessage(e, "LoadFiles")
scriptname.core.errormessage.ErrorMessage
Any ideas how the fix this?
Thanks
except Exception, e:syntax? The new syntax is supported from 2.6, which is now over 8 years old.LoadFilesa class? It looks like a function to me.