本文介绍了我要用cerr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否在良好的风格下使用cerr在下面描述的情况?
Is it in good style do use cerr in situation described below?
try
{
cout << a + b;
}
catch(const IntException& e)
{
cerr << "Exception caught: " << typeid(e).name(); //using cerr not cout
}
catch(...)
{
cerr << "Unknown exception.";//using cerr not cout
}
用过的?请参阅代码中的注释。
or cout should be used? See comments in code.
推荐答案
stderr
错误消息(所以OS / shell /任何可以捕获错误消息分开正常输出),所以是,使用 std :: cerr
!
stderr
is the traditional stream to send error messages (so that the OS/shell/whatever can capture error messages separately from "normal" output), so yes, use std::cerr
!
我没有评论是否捕获异常只是打印出来,只是让异常传播出你的应用程序...
I make no comment as to whether catching an exception simply to print it out is any better than simply letting the exception propagating out of your application...
这篇关于我要用cerr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!