Adding some error trapping/tracing so that console.log and JS exceptions are available on stdout