杀生丸H 2022-09-29 14:34 采纳率: 0%
浏览 55

e.printStackTrace与log.error(e)区别

问题遇到的现象和发生背景

在try{}catch(){}中直接exception.printStackTrace();与log.error(exception)除了输出位置不同之外有没有其他区别?
比如输出结果上或者性能上

用代码块功能插入代码,请勿粘贴截图

public static void main(String[] args) {
try {
String txt = "";
String substring = txt.substring(1, 2);
} catch (Exception e) {
e.printStackTrace();
log.error("error:",e);
}
}

  • 写回答

3条回答 默认 最新

  • 游一游走一走 2022-09-29 14:51
    关注

    e.printStackTrace();直接输出到System.err
    log.error("error:",e);做了很多其他的处理,性能自然没那么高了,而且log可以通过配置的方式,输出到System.err,File,甚至是直接入库

    评论

报告相同问题?

问题事件

  • 创建了问题 9月29日

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度