文件打开/关闭状态引发意外异常
unexpected exception thrown for file open/close status
嗨,我有代码的样本
try {
ifs.open(sourceHtmlFile.c_str());
std::cout << ifs << "n" ;
if( !ifs ) ;
throw std::string("Could not open file");
} catch (std::string &ex) {
std::cout << ex << " !n";
}
o/p
当文件不存在时:如果->0引发预期的异常
当文件确实存在时如果->0xbfc885b4但它还是抛出了异常。
我想知道为什么它在两种情况下都抛出异常
谢谢,
在if
条件之后有一个额外的;
。这个分号终止了条件语句,所以throw
总是被执行。
相关文章:
- 处理多个异常集合的C++方法
- 我在c++代码中生成了一个运行时#3异常
- 孤立代码块在结构中引发异常
- C++中的赋值发生,尽管右侧出现异常
- 在C++中对T*类型执行std::move的意外行为
- 从构造函数抛出异常时如何克服内存泄漏
- 异常属于C++中的线程还是进程
- 当类定义不可见时捕获异常
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 处理除以零会导致<csignal>意外行为
- 为什么异常不退出程序?
- vscode下的Arduino代码出现意外编译错误
- 使用++运算符会导致意外的结果
- 如何避免意外异常导致的问题
- 来自异常声明的派生对象类型是否意外
- boost::asio::yield_context:意外forced_unwind异常
- 文件打开/关闭状态引发意外异常
- 使用POCO上传文件- SSL连接意外关闭异常
- 异常处理,c++中的意外终止符