I've wondered a bit on how to do good error/exception handling in plugins, is there some particular way that can be considered recommended?
An example
- Code: Select all
try:
# do some calculation or other stuff
pass
except ValueError:
# example of some "expected" error based on user input or other invalid input etc.
self.logger.error(u'There is something wrong in some input')
except:
# Unexpected error, should normally not happen
self.logger.error(u'An unexpected error happened. This is a more user-friendly description')
raise # re-raise the exception to get stack trace
Comments to this?
Another question, say the plugin discovers a critical error (in configuration, reading external files etc.) that makes it pointless to leave the plugin running. Is there a way to quit the plugin from within the plugin? I think it is mentioned in the documentation that raising an exception in __init__ will stop the plugin, is that a recommended way to handle such errors?
And say that a critical error is discovered later on, while the plugin is running, how should that best be handled?
Thanks!