JavaScript rethrowing an Exception preserving the stack trace

后端 未结 3 839
生来不讨喜
生来不讨喜 2021-01-19 12:17

In Chrome, when an exception occurs, it prints a stack trace to the console log. This is extremely useful, but unfortunately in cases where an exception has been rethrown th

3条回答
  •  生来不讨喜
    2021-01-19 12:32

    The best you can do is grab the original stack and print it. I use this in unit testing tools.

    try{
      ...
    }
    catch(e){
        console.log(e.stack);
        console.log(e.message);
        throw(e);
    }
    

提交回复
热议问题