I am developing a kind of multi purpose server using nodeJs (net,express,socketIo). Multipurpose means its receiving data which i will process later in a custom plugin, also written in nodejs. At start of the server theres a config loaded in which tells the application, which additional js files should be loaded using require. All the plugins containing a create function which returns an object. This object is pushed into an array for reference.
self.config.plugins.forEach(function(plugin){
var plugin = require(Path.join(pluginDir,plugin.name, index.js" )).create(self);
self.apps.push(plugin);
});
The plugins have to be inherit from a special base class and are following a special pattern (I would like to use something like c# style interfaces, but didn't find a solution yet).
Now my question :
If there is an error in any of my plugins the whole application will crash. How can I achieve an error handling without putting each of my plugins methods into a try/catch statement ?
I hope somebody understands my problem, and could guide me in the right direction
You can use a process uncaughtException event: http://nodejs.org/api/process.html#process_event_uncaughtexception , but it is recommended to use try/catch statements and throwing errors where something goes in an undesired way, these try/catch statements should placed there where you are using content from modules.