Chrome:将例外情况详细信息打印到控制台 [英] Chrome: Print exception details to console

查看:73
本文介绍了Chrome:将例外情况详细信息打印到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的代码中在chrome devtools中打印Exception的堆栈跟踪?

How do I print the stack trace of an Exception in the chrome devtools from my code?

我尝试了以下操作:

 function doSomething() { 
     undefined(); // This throws an exception
 }

 try {
      doSomething();
 } catch (e) {
      console.error("Exception thrown", e);
 }

但这会产生以下结果:

 Exception thrown TypeError {}

如果我展开箭头旁边的箭头,它将指向指向console.error()调用的行,因此我看不到原始错误的实际发生位置.

And if I expand the arrow next to it, it points me to the line where the console.error() call was made, so I don't get to see where the original error actually happened.

在控制台输出中包括原始错误信息(包括消息和完整的堆栈跟踪,以精确到发生错误的位置)的最佳方法是什么?

What would be the best way to include the original error information (including message and complete stack trace to the exact location where the error happened) in the console output?

推荐答案

对象

Object Error has a property stack. Print it out.

console.error("Exception thrown", e.stack);

请注意,stack属性未标准化,仅由基于V8的浏览器+ IE使用. Firefox使用不同的约定.

Please note that stack property is not standardized and it is only used by V8 based browsers + IE. Firefox uses different convention.

这篇关于Chrome:将例外情况详细信息打印到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆