不满足条件时如何引发异常

我有这段代码:

class dataTable extends HTMLElement {
    constructor() {
        super();

        //Get our data
        this.dataList = data.dataList;
        this.dataHeaders = data.headers;

        //HTML attribute for creating our table
        this.html = "<table><tr>";
    }

    createtable() {
        //Items we want per roq
        var perRow = 2;

        //Loop through our data
        for (var i = 0; i < this.dataList; i++) {
            //Add our headers first
            this.html += "<td>" + this.dataHeaders[i] + "</td>";
            //Then add the corresponding piece of data
            this.html += "<td>" + this.dataList[i] + "</td>";
            //Decide when to break into the next row
            var next = i+1;

            if (next % perRow == 0 && next != this.dataList.length) {
                //Add the end row HTML
                this. html += "</tr><tr>"
            }
        }
        //End the table
        this.html += "</tr><table>";

        document.getElementById("container").innerHTML = this.html;
    }
}

我在其中验证该元素是否可见(使用'waitElmBecomeInvisible'),如果该元素不可见,我将返回一条消息来表明这一点。 如果该元素可见,我想抛出异常,则不确定应该抛出哪个异常,这就是你们可以建议我的一点,您认为我应该实现什么异常

zczhouzhiwei 回答:不满足条件时如何引发异常

由于这种情况只能在运行时发生(未选中此异常)-创建自己的ElementStillVisibleException extends RuntimeException似乎是合理的 扔掉。

本文链接:https://www.f2er.com/3166002.html

大家都在问