作家
登录

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

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

as eval] (domain.js:293:12)  
  1. function c() { 
  2.  
  3.     console.log('c'); 
  4.  
  5.  
  6.   
  7.  
  8. function b() { 
  9.  
  10.     console.log('b'); 
  11.  
  12.     c(); 
  13.  
  14.     console.trace(); 
  15.  
  16.  
  17.   
  18.  
  19. function a() { 
  20.  
  21.     console.log('a'); 
  22.  
  23.     b(); 
  24.  
  25.  

正如所看到的, 函数 c 运行完成之后, 已经大年夜客栈的顶部被移除.

  1. Trace 
  2.  
  3.     at b (repl:4:9) 
  4.  
  5.     at a (repl:3:1) 
  6.  
  7.     at repl:1:1  // <-- For now feel free to ignore anything below this point, these are Node's internals 
  8.  
  9.     at realRunInThisContextScript (vm.js:22:35) 
  10.  
  11.     at sigintHandlersWrap (vm.js:98:12) 
  12.  
  13.     at ContextifyScript.Script.runInThisContext (vm.js:24:12) 
  14.  
  15.     at REPLServer.defaultEval (repl.js:313:29) 
  16.  
  17.     at bound (domain.js:280:14) 
  18.  
  19.     at REPLServer.runBound [as eval] (domain.js:293:12) 
  20.  
  21.     at REPLServer.onLine (repl.js:513:10)  

Error对象和缺点处理

  1. function c() { 
  2.  
  3.     console.log('c'); 
  4.  
  5.     console.trace(); 
  6.  
  7.  
  8.   
  9.  
  10. function b() { 
  11.  
  12.     console.log('b'); 
  13.  
  14.     c(); 
  15.  

  16.   推荐阅读

      关于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)