C++ std :: filesystem :: copy抛出怪异的例外:commonutil :: chresultexceptionimpl
这是一个特定于Windows的问题。
我正在尝试使用std :: Filesystem :: copy()
将目录的内容复制到另一个目录。
当调试到我的C ++程序时,我注意到执行std :: filesystem :: copy()
之后发生了一个奇怪的例外。只有在调试而无法捕获时才能看到此例外。
我用其他目录对其进行了测试,但没有发生例外。
这是例外的方式:
我从称为test_fail
构造的目录中复制内容:
test_fail
|
----------------------------------------------
| |
Subdirectory Subdirectory
| |
-------------- -------------------------
| | |
1 file 7 files Subdirectory
-------------
|
3 files
复制的内容将进入一个空名,称为test 。
每个文件的大小为1 kb (每个文件中只有字符串“ hello”)
这是我的代码:
#include <filesystem>
#include <string>
namespace fs = std::filesystem;
int main() {
// The path of the Directory that produces the exception : CommonUtil::CHResultExceptionImpl
std::string failing_Directory = "C:\\Users\\Ibrahim\\test_fail";
// Copying the failing Directory to specifed directory in a try block ,
// instead of catching the exception it just copies the contents and the function returns.
// I'm using options "fs::copy_options::recursive | fs::copy_options::overwrite_existing"
// to copy all files as well as subdirectories to the specified location as well as overwrite
// any overwrite the existing directories and files that are duplicates
try {
fs::copy(failing_Directory, "C:\\Users\\Ibrahim\\test", fs::copy_options::recursive | fs::copy_options::overwrite_existing);
}
catch (std::exception &e) {
// The Program doesnt enter this catch
printf(e.what());
return -1;
}
// The Program Exits Normally
}
发生例外的屏幕截图:
您可以看到异常仅出于某种原因在调试时发生。
尽管我的代码在例外效果很好,但是为什么会发生这种情况?
这是Visual Studio中的错误吗?
谢谢
This is a Windows specific problem.
I am trying to use std::filesystem::copy()
to copy a directory's contents to another directory.
When debugging into my C++ program , I notice that a weird exception occurs after executing std::filesystem::copy()
. This exception can only be seen when debugging and can't be caught.
I tested it with other directories and the exception didn't occur for them.
Here is how The exception occurs :
I copy the contents from a directory called test_fail
structured like so :
test_fail
|
----------------------------------------------
| |
Subdirectory Subdirectory
| |
-------------- -------------------------
| | |
1 file 7 files Subdirectory
-------------
|
3 files
The copied contents will go into an empty directory called test
.
Every file has is 1 KB of size (Every file only has the string "hello" in it )
Here is my code :
#include <filesystem>
#include <string>
namespace fs = std::filesystem;
int main() {
// The path of the Directory that produces the exception : CommonUtil::CHResultExceptionImpl
std::string failing_Directory = "C:\\Users\\Ibrahim\\test_fail";
// Copying the failing Directory to specifed directory in a try block ,
// instead of catching the exception it just copies the contents and the function returns.
// I'm using options "fs::copy_options::recursive | fs::copy_options::overwrite_existing"
// to copy all files as well as subdirectories to the specified location as well as overwrite
// any overwrite the existing directories and files that are duplicates
try {
fs::copy(failing_Directory, "C:\\Users\\Ibrahim\\test", fs::copy_options::recursive | fs::copy_options::overwrite_existing);
}
catch (std::exception &e) {
// The Program doesnt enter this catch
printf(e.what());
return -1;
}
// The Program Exits Normally
}
Screenshot of where the exception occurs :
You can see the exception occur only while debugging , for some reason .
Although my code works fine with the exception , why is this happening ?
Is this a bug in Visual Studio ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论