Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Error.prototype.columnNumber property

JavaScript Error.prototype.columnNumber property

The columnNumber is a non-standard property that contains the column number of the line at which the error was raised. It is recommended to not use this property on production sites facing the web, as it may not work for every user. 

Use: This property is useful while creating an error object. If the column number is undefined for any error object, you can define it manually.

Syntax:

error.columnNumber

Example 1:

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);
}


Output: 

Error: Format not supported
At Column number: 0

Example 2:

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);
}


Output: 

Error: Unexpected token output
At Column number: 0

Browser compatibility(Desktop): 

  • Firefox

Browser compatibility(Mobile): 

  • Firefox for Android

We have a complete list of Javascript Errors, to check those please go through the JavaScript Error Object Complete Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments