Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 680003 of Error.prototype.lineNumber

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Error/lineNumber
  • Revision title: Error.prototype.lineNumber
  • Revision id: 680003
  • Created:
  • Creator: paul.irish
  • Is current revision? No
  • Comment Better technique. Messy. sorry.

Revision Content

{{JSRef("Global_Objects", "Error", "EvalError,InternalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError")}} {{non-standard_header}}

Summary

The lineNumber property contains the line number in the file that raised this error.

Examples

Example: Using lineNumber

var e = new Error('Could not parse input');
throw e;
console.log(e.lineNumber) // 2

Alternative example using error event

window.addEventListener("error", function (e) {
    console.log(e.lineno); //5
});
var e = new Error('Could not parse input');
throw e;
This is standard and supported across Chrome, Firefox and likely more.

 

Specifications

Not part of any specification. Non-standard.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support On error object in handled errors {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

  • {{jsxref("Error.prototype.stack")}} {{non-standard_inline}}
  • {{jsxref("Error.prototype.columnNumber")}} {{non-standard_inline}}
  • {{jsxref("Error.prototype.fileName")}} {{non-standard_inline}}

Revision Source

<div>
 {{JSRef("Global_Objects", "Error", "EvalError,InternalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError")}} {{non-standard_header}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code><strong>lineNumber</strong></code> property contains the line number in the file that raised this error.</p>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Throwing_a_custom_error" name="Example:_Throwing_a_custom_error">Example: Using <code>lineNumber</code></h3>
<pre class="brush: js">
var e = new Error('Could not parse input');
throw e;
console.log(e.lineNumber) // 2
</pre>
<h3 id="Example:_error-event-lineno" name="Example:_Throwing_a_custom_error" style="line-height: 24px; font-size: 1.71428571428571rem;">Alternative example using error event</h3>
<pre class="brush: js">
window.addEventListener("error", function (e) {
    console.log(e.lineno); //5
});
var e = new Error('Could not parse input');
throw e;
</pre>
This is standard and supported across Chrome, Firefox and likely more.
<p>&nbsp;</p>
<h2 id="Specifications">Specifications</h2>
<p>Not part of any specification. Non-standard.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>On error object in handled errors</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
 <li>{{jsxref("Error.prototype.stack")}} {{non-standard_inline}}</li>
 <li>{{jsxref("Error.prototype.columnNumber")}} {{non-standard_inline}}</li>
 <li>{{jsxref("Error.prototype.fileName")}} {{non-standard_inline}}</li>
</ul>
Revert to this revision