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.