作家
登录

深入理解JavaScript错误和堆栈追踪

作者: 来源: 2017-04-25 17:10:21 阅读 我要评论

 REPLServer.runBound [as eval] (domain.js:293:12) 
  • //    at REPLServer.onLine (repl.js:513:10) 
  • 不知道你留意到没,我们起首调用了a(a入栈),然后我们a中又调用了b(b入栈且在a之上)。然后在b中我们捕获了当前客栈记录并将其存储在myObj中。是以在控制台中才会按照b a的次序打印客栈。

    如今让我们给Error.captureStackTrace传递一个函数作为第二个参数,看看会产生什么:

    1. const myObj = {}; 
    2.  
    3. function d() { 
    4.     // Here we will store the current stack trace into myObj 
    5.     // This time we will hide all the frames after `b` and `b` itself 
    6.     Error.captureStackTrace(myObj, b); 
    7.  
    8. function c() { 
    9.     d(); 
    10.  
    11. function b() { 
    12.     c(); 
    13.  
    14. function a() { 
    15.     b(); 
    16.  
    17. // First we will call these functions 
    18. a(); 
    19.  
    20. // Now let's see what is the stack trace stored into myObj.stack 
    21. console.log(myObj.stack); 
    22.  
    23. // This will print the following stack to the console: 
    24. //    at a (repl:2:1) <-- As you can see here we only get frames before `b` was called 
    25. //    at repl:1:1 <-- Node internals below this line 
    26. //    at realRunInThisContextScript (vm.js:22:35) 
    27. //    at sigintHandlersWrap (vm.js:98:12) 
    28. //    at ContextifyScript.Script.runInThisContext (vm.js:24:12) 
    29. //    at REPLServer.defaultEval (repl.js:313:29) 
    30. //    at bound (domain.js:280:14) 
    31. //    at REPLServer.runBound [as eval] (domain.js:293:12) 
    32. //    at REPLServer.onLine (repl.js:513:10) 
    33. //    at emitOne (events.js:101:20) 

    当把b传给Error.captureStackTraceFunction时,它隐蔽了b本身以及它之后所有的调用帧。是以控制台仅仅打印出一个a。


      推荐阅读

      深度卷积神经网络在目标检测中的进展

    近些年来,深度卷积神经收集(DCNN)在图像分类和辨认上取得了很明显的进步。回想大年夜 2014 到 2016 这两年多的时光,先后出现出了 R-CNN,Fast R-CNN, Faster R-CNN, ION, HyperNet, SD>>>详细阅读


    本文标题:深入理解JavaScript错误和堆栈追踪

    地址:http://www.17bianji.com/lsqh/34953.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)