Report pending exception after JS syntax error.

Addresses review comments by Ms2ger on #2863.