断言不会显示错误消息
我在 Visual C++ 2005 中遇到了断言的奇怪问题。我尝试将断言引入到我的程序中,无论我尝试使用什么断言(assert() 或 BOOST_ASSERT_MSG),它都会给出完全相同的错误消息,告诉我除了发生调试错误之外没有其他任何事情。
调试错误!
程序:...
此应用程序已请求运行时以异常方式终止它。 请联系支持团队以获取更多信息。
(按“重试”来调试应用程序)
这是我正在使用的升压断言
BOOST_ASSERT_MSG(deathRow.size() >= 3, "There are less than 3 blocks being deleted!");
,是的,它给出了与以下完全相同的错误消息:
assert(deathRow.size() >= 3 && "There are less than 3 blocks being deleted");
无论我使用什么项目,新的还是旧的,都会发生不伦不类的错误。
我不知道为什么。我知道我之前在另一个程序中使用过断言并且没有这个问题。如有帮助,将不胜感激。
I'm having a weird problem with assert in Visual C++ 2005. I've tried to introduce asserts into my program and no matter what asserts I try to use (assert() or BOOST_ASSERT_MSG) it gives the exact same error message which tells me nothing other than that a debug error occurred.
Debug Error!
Program: ...
This application has requested the Runtime to terminate it in an unusual way.
Please contact the support team for more information.(Press Retry to Debug the application)
Here's the boost assertion that I'm using
BOOST_ASSERT_MSG(deathRow.size() >= 3, "There are less than 3 blocks being deleted!");
And yes, it gives the exact same error message as:
assert(deathRow.size() >= 3 && "There are less than 3 blocks being deleted");
Nondescript error happens, no matter what project I'm using, new or old.
I have no idea why. I know I used asserts before in another program and didn't have this problem. Help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 Microsoft 的
_ASSERTE
宏(注意E 代表表达式),那么该消息也将出现在断言对话框中。ASSERT
两个版本存在的原因是两者都有优点和缺点,您可以选择您想要的。_ASSERTE
提供更好的诊断,但会产生稍大的二进制文件(因为表达式的文本表示必须包含在二进制文件中)_ASSERT
在断言对话框中提供较少的信息,但会导致较小的二进制文件。由于这两种风格仅在调试构建中生成代码,因此我倾向于始终使用 _ASSERTE ,因为二进制文件的大小几乎不会受到影响,并且在调试构建中并不重要。
If you use Microsoft's
_ASSERTE
macro (note the E for Expression) then the message will also appear in assert dialog.The reason both versions of
ASSERT
exist is that both have advantages and disadvantages and you get to choose which you want._ASSERTE
gives better diagnostics but results in slightly bigger binaries (since the textual representation of the expression must be included in the binary)_ASSERT
give less information in the assert dialog but results in smaller binaries.Since both flavours only produce code in debug build I tend to always use
_ASSERTE
because the size of the binary is hardly effected and doesn't matter much in debug builds.