JavaScript Error.prototype.columnNumber property
Last Updated :
10 Feb, 2023
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 {
var err = new Error ( "Format not supported" , "filename" ,0);
if (err.columnNumber == undefined)
err.columnNumber = 0;
throw err;
}
catch (e) {
console.log ( "Error: " + e.message);
console.log ( "At Column number: " + e.columnNumber);
}
|
Output:
Error: Format not supported
At Column number: 0
Example 2:
Javascript
try {
var err = new Error ( "Unexpected token output" , "filename" ,0);
if (err.columnNumber == undefined)
err.columnNumber = 0;
throw err;
}
catch (e) {
console.log ( "Error: " + e.message);
console.log ( "At Column number: " + e.columnNumber);
}
|
Output:
Error: Unexpected token output
At Column number: 0
Browser compatibility(Desktop):
Browser compatibility(Mobile):
We have a complete list of Javascript Errors, to check those please go through the JavaScript Error Object Complete Reference article.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...