What is the appropriate python Exception to raise if there is a missing settings file?
For example, in Django projects, a light-weight way to allow users to define local settings is to add the following snippet to the settings.py file
try:
from local_settings import *
except ImportError:
# want to add informative Exception here
pass
thus, any local settings override the defaults in settings.py.
The usual exception for missing files is IOError.
You can customize the wording by creating a subclass:
class MissingSettingsFile(IOError):
'Missing local settings file'
pass
Then, use that custom exception in your code snippet:
try:
from local_settings import *
except ImportError:
raise MissingSettingsFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With