emit errors instead of calling process.exit()

Improvement to #520 error handling

More discussion on this approach in #425