作家
登录

JavaScript错误处理和堆栈追踪浅析

作者: 来源: 2017-04-07 09:18:02 阅读 我要评论

current stack trace into myObj 
  •  
  •     // This time we will hide all the frames after `b` and `b` itself 
  •  
  •     Error.captureStackTrace(myObj, b); 
  •  
  •  
  •   
  •  
  • function c() { 
  •  
  •     d(); 
  •  
  •  
  •   
  •  
  • function b() { 
  •  
  •     c(); 
  •  
  •  
  •   
  •  
  • function a() { 
  •  
  •     b(); 
  •  
  •  
  •   
  •  
  • // First we will call these functions 
  •  
  • a(); 
  •  
  •   
  •  
  • // Now let's see what is the stack trace stored into myObj.stack 
  •  
  • console.log(myObj.stack); 
  •  
  •   
  •  
  • // This will print the following stack to the console: 
  •  
  • //    at a (repl:2:1) <-- As you can see here we only get frames before `b` was called 
  •  
  • //    at repl:1:1 <-- Node internals below this line 
  •  
  • //    at realRunInThisContextScript (vm.js:22:35) 
  •  
  • //    at sigintHandlersWrap (vm.js:98:12) 
  •  
  • //    at ContextifyScript.Script.runInThisContext (vm.js:24:12) 
  •  
  • //    at REPLServer.defaultEval (repl.js:313:29) 
  •  
  • //    at bound (domain.js:280:14) 
  •  
  • //    at REPLServer.runBound [as eval] (domain.js:293:12) 
  •  
  • //    at REPLServer.onLine (repl.js:513:10) 
  •  

      推荐阅读

      关于JavaScript的数组随机排序

    JavaScript 开辟中有时会碰到要将一个数组随机排序(shuffle)的需求,一个常见的写法是如许:function shuffle(arr) { arr.sort(function () { return Math.random() - 0.5; >>>详细阅读


    本文标题:JavaScript错误处理和堆栈追踪浅析

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

  • 关键词: 探索发现

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

    网友点评
    自媒体专栏

    评论

    热度

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