[Javascript] Error Cause

class Product {
    name;
    price;
    constructor(name, price) {
        this.name = name;
        try {
            this.price = price * 1.30;
        } catch(e) {
            throw new Error("Product cannot be created", {cause: e})
        }
    }
}

When you throw the error, also mention where is the cause of original error by using cause

posted @ 2024-08-11 22:03  Zhentiw  阅读(9)  评论(0)    收藏  举报