Move error event catching earlier, so we can catch syntax errors.