📜  JavaScript Error.prototype.columnNumber 属性

📅  最后修改于: 2022-05-13 01:56:24.839000             🧑  作者: Mango

JavaScript Error.prototype.columnNumber 属性

columnNumber 是一个非标准属性,它包含引发错误的行的列号。建议不要在面向 Web 的生产站点上使用此属性,因为它可能不适用于每个用户。

使用:此属性在创建错误对象时很有用。如果任何错误对象的列号未定义,您可以手动定义它。

句法:

error.columnNumber
Javascript
try {
    // Creating a new error object
    var err = new Error ("Format not supported","filename",0);
    if(err.columnNumber == undefined)
        err.columnNumber = 0;
    throw err;
}
catch(e) {
    // Printing error message
    console.log ("Error: " + e.message);
    // Printing column number of line
    // at which error was raised
    console.log ("At Column number: " + e.columnNumber);
}


Javascript
try {
    // Creating new error object
    var err = new Error ("Unexpected token output","filename",0);
    if(err.columnNumber == undefined)
        err.columnNumber = 0;
    throw err;
}
catch(e) {
    // Printing error message
    console.log ("Error: " + e.message);
    // Printing column number of line
    // at which this error was raised
    console.log ("At Column number: " + e.columnNumber);
}


输出:

Error: Format not supported
At Column number: 0

Javascript

try {
    // Creating new error object
    var err = new Error ("Unexpected token output","filename",0);
    if(err.columnNumber == undefined)
        err.columnNumber = 0;
    throw err;
}
catch(e) {
    // Printing error message
    console.log ("Error: " + e.message);
    // Printing column number of line
    // at which this error was raised
    console.log ("At Column number: " + e.columnNumber);
}

输出:

Error: Unexpected token output
At Column number: 0

浏览器兼容性(桌面):

  • 火狐

浏览器兼容性(移动):

  • 火狐安卓版