【问题标题】:What is this err here?这是什么错误?
【发布时间】:2020-10-24 19:53:10
【问题描述】:

const HttpError = require("../models/http-error");

//http-error.js
class HttpError extends Error {
    constructor(message, errorCode) {
        super(message); // Add a "message" property
        this.code = errorCode; // Adds a "code" property
    }
}

module.exports = HttpError;

errerror有什么区别err

【问题讨论】:

  • err 是从 Place.findById 抛出的,而 error 只是一个常量,您定义它不抛出并且不会在范围内,而是应该抛出它...... down if(!place) 实际上是在抛出但你没有缓存它,假设你有一个外部错误处理程序

标签: javascript error-handling syntax-error


【解决方案1】:

err 是一个可选标识符,用于保存关联的 catch 块的异常对象。 MDN try...cactch

const error 是您的自定义错误处理程序的对象

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多