[core/errors] Add custom exceptions
Add custom exceptions and add error handling to the engine's module loading logic. I.e. when a non-existent module is loaded, an exception is thrown now. see #23
This commit is contained in:
parent
b6eb3ee8e6
commit
8855f1155b
4 changed files with 33 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
"""Core application engine"""
|
||||
|
||||
import time
|
||||
import importlib
|
||||
import bumblebee.error
|
||||
|
||||
class Module(object):
|
||||
"""Module instance base class
|
||||
|
@ -33,7 +35,10 @@ class Engine(object):
|
|||
|
||||
def load_module(self, module_name):
|
||||
"""Load specified module and return it as object"""
|
||||
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
|
||||
try:
|
||||
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
|
||||
except ImportError as error:
|
||||
raise bumblebee.error.ModuleLoadError(error)
|
||||
return getattr(module, "Module")(self)
|
||||
|
||||
def running(self):
|
||||
|
@ -53,6 +58,7 @@ class Engine(object):
|
|||
widgets += module.widgets()
|
||||
self._output.draw(widgets)
|
||||
self._output.flush()
|
||||
time.sleep(1)
|
||||
|
||||
self._output.stop()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue