Get error line number in JScript in Windows Script Host

Let's say I have the following code that I run as a .JS file using the Windows Script Host:

try { ProduceAnError(); } catch(e) { //How to get an error line here? } 

Is there any way to find out the error line in which the error occurred (exception)?

+4
source share
2 answers

Sorry for my other answer. It was not very useful: P

I believe you are looking for a property of the ReferenceError stack. You can access it with the argument you pass catch:

 try { someUndefinedFunction("test"); } catch(e) { console.log(e.stack) } 

Output Example:

  ReferenceError: someUndefinedFunction is not defined at message (http://example.com/example.html:4:3) at <error: TypeError: Accessing selectionEnd on an input element that cannot have a selection.> at HTMLInputElement.onclick (http://example.com/example.html:25:4) 
+1
source

There really is no way to get the stack or even print the line number programmatically. When an error is generated, only the line number can be seen. At best, you can get an error code and description, or you can make your own mistakes.

Here is the documentation .

And an example

 try { produceAnError(); } catch(e) { WScript.echo((e.number>>16 & 0x1FFF)); // Prints Facility Code WScript.echo((e.number & 0xFFFF)); // Prints Error Code WScript.echo(e.description); // Prints Description throw e; } 
0
source

All Articles