console.log 在函数后面出现错误时不起作用

console.log doesn't work when there's an error later in the function

我正在尝试使用 console.log 语句调试 Express.js 中的一些代码。但是,似乎只要函数中有错误,即使错误发生在console.log语句之后,console.log语句中的none也会执行。这是为什么?

我逐行注释掉了该函数,发现如果后面的一行被注释掉,console.log 语句就可以工作,但如果没有,则什么也不会打印出来。如果 console.log 没有阻塞,console.warn 和 console.error 也不起作用。

async delete(id) {
    console.error("repo");
    let color = await this.get(id);
    console.warn(color);
    let event = await this.events.create("Delete Color", 1,
      this.name, color.name);
    const color = await this._delete({ where: { id }}, true,
      { eventId: event.id }); // this is where the error occurs
    await this.events.done(event.id);
    return color;
  }

我希望 console.log,或者至少 console.warn 和 console.error 是阻塞的,这样它们应该按顺序执行。由于包含 this._delete() 的行晚于 console.error 和 console.warn 语句,因此无论该函数是否有效,它都应该在控制台中打印出来。但事实并非如此。

正如 charlietfl 评论的那样,由于变量 color 已经被声明,整个函数是不正确的。

该错误不是运行时错误,而是 SyntaxError,导致函数根本无法执行。