【发布时间】:2017-12-24 10:43:02
【问题描述】:
文件流析构函数能否抛出异常,例如,如果文件关闭操作失败?
auto f = new std::ofstream("data.txt");
f->exceptions(std::ofstream::failbit | std::ofstream::badbit);
...
delete f; // May throw?
我可以通过手动关闭流来防止此类异常吗?
auto f = new std::ofstream("data.txt");
f->exceptions(std::ofstream::failbit | std::ofstream::badbit);
...
f->close();
delete f; // May throw?
【问题讨论】:
-
没有标准的类从它的析构函数中抛出,你的也不应该。
标签: c++ exception destructor throw filestreams