适用于 C++ 的智能断言应用?
定义一个新的宏是否会满足我向用户显示失败断言的需要,并为开发人员提供足够的信息来调试问题,这是否很好?
给用户的消息,什么 用户应该将此消息作为开发人员的最后信息
#define ASSERT(f) \
do \
{ \
if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
AfxDebugBreak(); \
} while (0) \
用户应该在我们使用的
MessageBox(_T("Error in finding file."),_T("TITLE"),MB_ICONERROR);
Is it good to define a new macro that craters my need of showing failed assertion to user and with just enough information for developers to debug the issue.
Message for user, what the
user should do with this message at last information for the developer
#define ASSERT(f) \
do \
{ \
if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
AfxDebugBreak(); \
} while (0) \
sample message fn that we use,
MessageBox(_T("Error in finding file."),_T("TITLE"),MB_ICONERROR);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
消息框不得向开发人员显示任何信息。开发人员的信息必须保存在某些日志文件中,并且用户要求将文件传输给开发人员。
PS:你的问题太短了。
Message Box MUST NOT show any information for developers. information for developers must be saved in some log-file and user asked for transmit file to developer.
PS: You question is extremely short.
从最终用户的角度来看,我会考虑一些事情。
我想说,强制用户弹出断言显然是个坏主意,但允许他们启用或禁用警告将是一个好方法。
There's a couple things I would consider from the end-user's standpoint.
I'd say that forcing the assertion popups on users would be a plain bad idea, but allowing them to enable or disable the warnings would be a good approach.
就在问这个问题后,我读到了 Andrei Alexandrescu 和 John Torjo 在 中提到的
SMART_ASSERT
增强断言。这看起来对我来说是正确的选择,但是该文章中的源链接已损坏,有人可以给我 SMART_ASSERT 的源代码吗?Just after asking this question I read about
SMART_ASSERT
mentioned by Andrei Alexandrescu and John Torjo in Enhancing Assertions.This looks like that is right candidate for me, but the link to the source in that article is broken, can someone give me the source code for SMART_ASSERT?永远不要向用户暴露任何内部结构,除非他们都是程序员,而是使用日志文件和弹出窗口,并建议将这些日志发送(自动)给开发人员。
Never expose any internals to users unless they are all programmers instead use log-files and pop-up with proposition of sending(automatically) those logs to devs.
我不会让用户看到任何真正的调试信息,因为它只会让你的应用程序看起来很成熟。
其次,为什么使用 do-while 循环而不是常规的 {} 作用域?
I would not let users see any real debug info, as it will only make your application look amature.
Secondly, why are you using a do-while loop instead of a regular {} scope ?