SERVER-8553: fix v8 error checking and exception handling