Javascript 节点异常显示格式

Javascript 节点异常显示格式,javascript,node.js,exception,Javascript,Node.js,Exception,在Node.js中,当您抛出异常但未捕获它时,默认情况下会出现如下显示: C:\tptp-parser\index.js:19 throw e ^ SyntaxError: Unknown language (33:7) at err (C:\tptp-parser\index.js:14:10) at Object.parse (C:\tptp-parser\index.js:354:5) at read (C:\tptp-parser

在Node.js中,当您抛出异常但未捕获它时,默认情况下会出现如下显示:

C:\tptp-parser\index.js:19
        throw e
        ^

SyntaxError: Unknown language (33:7)
    at err (C:\tptp-parser\index.js:14:10)
    at Object.parse (C:\tptp-parser\index.js:354:5)
    at read (C:\tptp-parser\tptp-parser.js:14:15)
    at Object.<anonymous> (C:\tptp-parser\tptp-parser.js:37:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
C:\tptpparser\index.js:19
掷e
^
语法错误:未知语言(33:7)
at err(C:\tptpparser\index.js:14:10)
在Object.parse(C:\tptpparser\index.js:354:5)
读取时(C:\tptpparser\tptpparser.js:14:15)
反对。(C:\tptpparser\tptpparser.js:37:3)
在模块处编译(Module.js:570:32)
在Object.Module.\u extensions..js(Module.js:579:10)
在Module.load(Module.js:487:32)
在tryModuleLoad时(module.js:446:12)
在Function.Module.\u加载(Module.js:438:3)
位于Module.runMain(Module.js:604:10)
前三行是源代码中引发异常的位置,然后是消息,然后是堆栈跟踪。我知道如何定制消息(如上面的示例所示);有没有办法同时定制前三行


也就是说,我正在编写一个解析器,如果我可以更改前三行来显示,而不是解析器中的代码行,而是正在解析的文件中的文本行,那将是非常理想的。有没有办法做到这一点?

SyntaxError
是一个
nodejs
内置函数

从repl调用它将返回:

> SyntaxError('here')
SyntaxError: here
  at SyntaxError (native)
  at repl:1:1
  at sigintHandlersWrap (vm.js:22:35)
  at sigintHandlersWrap (vm.js:96:12)
  at ContextifyScript.Script.runInThisContext (vm.js:21:12)
  at REPLServer.defaultEval (repl.js:346:29)
  at bound (domain.js:280:14)
  at REPLServer.runBound [as eval] (domain.js:293:12)
  at REPLServer.<anonymous> (repl.js:545:10)
  at emitOne (events.js:101:20)
>语法错误('here')
SyntaxError:在这里
在SyntaxError(本机)
回复:1:1
在sigintHandlersWrap(vm.js:22:35)
在sigintHandlersWrap(vm.js:96:12)
在ContextifyScript.Script.runInThisContext(vm.js:21:12)
在REPLServer.defaultEval(repl.js:346:29)
绑定时(domain.js:280:14)
在REPLServer.runBound[as eval](domain.js:293:12)
在服务器上。它允许您自定义解析过程中抛出的错误