何时记录一个被捕获的异常的堆栈跟踪 [英] When to log a stacktrace for a caught exception

查看:100
本文介绍了何时记录一个被捕获的异常的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近询问了是否报告 getMessage()发生异常的文本。相当令人惊讶的是,大多数答案误解了我的问题,并且认为我是否询问是否报告一个捕获异常的堆栈跟踪,这表明这样做被认为是常态。所以我在问一个跟进问题。

I recently asked whether to report the getMessage() text of a caught exception. Rather surprisingly, most answers misunderstood my question and thought I was asking whether to report the stack-trace for a caught exception, suggesting that doing so is considered the norm. So I'm asking a follow up question.

当你 c> catch时,你应该在哪种情况下或者不应该报告一个堆栈跟踪一个例外?通过报告,我将询问日志框架为您记录堆栈跟踪

In which circumstances should you, or should you not, report a stack-trace when you catch an exception? By "reporting" I include asking a logging framework to log the stack-trace for you.

编辑:我不问是否报告某些东西。我问这个报告是否应该包含堆栈跟踪。

I not asking whether to report something. I'm asking whether that report should include the stack-trace.

推荐答案

它与上下文相关。例如,当从外部系统解析输入时,我可能不会从NumberFormat中记录/报告ParseException,但是如果我遇到了一个ParseException,那么这个ParseException是处理我系统边界内的数据,因为这将指示一个内部系统状态不一致,而不是输入值验证失败。

It's context dependent. For example, I might not log / report a ParseException from NumberFormat when parsing input from an external system, but I would definitely do so if I caught a ParseException which was dealing with data enclosed within the boundary of my system, since this would indicate an inconsistency in internal system state rather than an input value validation falure.

这篇关于何时记录一个被捕获的异常的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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