Create function emitError to reference when removing events

Created function emitError to reference when an uncaught exception
event is added to the main process.  The reference is used when
shutdown is called so it can be cleanly removed using
removeListener