Exception code: 0xc0000409

Oct 26, 2020 at 7:23pm
So I wrote a beginner's program to wipe out some files and copy some updated ones in their place. I used ALOT of system( ) commands and decided now it was time to put some bigger boy pants on and do things right. Well tried to use filesystem. It starts to remove the contents of the first directory then crashes.

This is the event log from Windows:

Faulting application name: Alter_MP_Folders.exe, version: 0.0.0.0, time stamp: 0x5f971c2c
Faulting module name: ucrtbase.dll, version: 10.0.18362.1110, time stamp: 0x100b54ae
Exception code: 0xc0000409
Fault offset: 0x0009efbb
Faulting process id: 0x3ff8
Faulting application start time: 0x01d6abcc3474ae4b
Faulting application path: C:\Users\sboudreaux.SSI-LT33\Desktop\MP Test\Alter_MP_Folders.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report Id: ebe3d0ac-9ded-4c35-b742-c8e864d07c08
Faulting package full name:
Faulting package-relative application ID:

Trying to figure out what is going on here. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//


#include <iostream>
#include <time.h>
#include <Windows.h>
#include <filesystem>
using namespace std;

int main()
{
	
	cout << endl << endl << "   Altering Media Player Folders... Please wait..." << endl << endl << endl << endl;

	Sleep(2000);

	std::filesystem::remove_all("c:/synergyii/cdDefaultContents/");
	std::filesystem::remove_all("c:/synergyii/h264cdDefaultContents/");
	std::filesystem::remove_all("c:/synergyii/mediaplayer/");


	Sleep(2000);

	std::filesystem::create_directory("c:/synergyii/cdDefaultContents/");
	std::filesystem::create_directory("c:/synergyii/h264cdDefaultContents/");
	std::filesystem::create_directory("c:/synergyii/mediaplayer/");

	Sleep(2000);
	std::filesystem::copy("MPFiles/", "c:/synergyii/cdDefaultContents/", std::filesystem::copy_options::recursive);
	Sleep(2000);
	std::filesystem::copy("MPFiles/", "c:/synergyii/h264cdDefaultContents/", std::filesystem::copy_options::recursive);
	Sleep(2000);
	std::filesystem::copy("MPFiles/", "c:/synergyii/mediaplayer/", std::filesystem::copy_options::recursive);
	Sleep(2000);

	cout << endl << endl << "   Process Completed!" << endl << endl << endl << endl;

	Sleep(3000);

	
	return 0;
}
Oct 26, 2020 at 7:59pm
Put this around everything in main():
1
2
3
4
5
6
7
8
9
10
int main()
{
    try{
        //...
    }catch (std::exception &e){
        std::cerr << e.what() << std::endl;
        return -1;
    }
    return 0;
}
What does it print?
Oct 26, 2020 at 9:55pm
It's not printing anything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//


#include <iostream>
#include <time.h>
#include <Windows.h>
#include <filesystem>
using namespace std;

int main()
{
	try {

		cout << endl << endl << "   Altering Media Player Folders... Please wait..." << endl << endl << endl << endl;

		Sleep(2000);

		std::filesystem::remove_all("c:/synergyii/cdDefaultContents/");
		std::filesystem::remove_all("c:/synergyii/h264cdDefaultContents/");
		std::filesystem::remove_all("c:/synergyii/mediaplayer/");


		Sleep(2000);

		std::filesystem::create_directory("c:/synergyii/cdDefaultContents/");
		std::filesystem::create_directory("c:/synergyii/h264cdDefaultContents/");
		std::filesystem::create_directory("c:/synergyii/mediaplayer/");

		Sleep(2000);
		std::filesystem::copy("MPFiles/", "c:/synergyii/cdDefaultContents/", std::filesystem::copy_options::recursive);
		Sleep(2000);
		std::filesystem::copy("MPFiles/", "c:/synergyii/h264cdDefaultContents/", std::filesystem::copy_options::recursive);
		Sleep(2000);
		std::filesystem::copy("MPFiles/", "c:/synergyii/mediaplayer/", std::filesystem::copy_options::recursive);
		Sleep(2000);

		cout << endl << endl << "   Process Completed!" << endl << endl << endl << endl;

		Sleep(3000);


		return 0;
	}

	catch (std::exception &e){
		std::cerr << e.what() << std::endl;
		return -1;
	}
	return 0;
}
Oct 27, 2020 at 4:06am
Is it still generating the event on system logs?
Oct 27, 2020 at 10:03am
The code works fine for me on Windows 7 64bit Pro with VS 2019.
Oct 27, 2020 at 12:46pm
It is still generating the event in the system logs.

That is the weird thing, it will run sometimes but not every time.

I ran it through the debugger in Visual Studio and got this

Exception thrown at 0x775E4662 in Alter_MP_Folders.exe: Microsoft C++ exception: std::filesystem::filesystem_error at memory location 0x005CF828.
Unhandled exception at 0x775E4662 in Alter_MP_Folders.exe: Microsoft C++ exception: std::filesystem::filesystem_error at memory location 0x005CF828.

and that is marked on the line:

std::filesystem::remove_all("c:/synergyii/cdDefaultContents/");

Which leads me to be live there is something up with the filesystem function and that I am missing something.
Oct 27, 2020 at 1:11pm
There are 2 version of std::filesystem::remove_all. One throws an exception, another one return an error code. Maybe try the second on.
https://en.cppreference.com/w/cpp/filesystem/remove

About: Exception code: 0xc0000409
https://www.minitool.com/news/0xc0000409.html
Oct 27, 2020 at 1:15pm
Hello Vendetto,

Kind of thinking out loud here.

In your line of code: std::filesystem::remove_all("c:/synergyii/cdDefaultContents/");. Is there anything in the 2 sub-directories that is misspelled?

Is the final (/) actually needed? This 1 I am not sure about.

Andy
Oct 27, 2020 at 1:59pm
For windows, \ is the name delimiter, not /

So
 
std::filesystem::remove_all("c:/synergyii/cdDefaultContents/");


becomes:

 
std::filesystem::remove_all("c:\\synergyii\\cdDefaultContents\\");


\\ is needed as \ is the escape char so \\ is actually just \

Oct 27, 2020 at 2:04pm
Do you have evidence that your suggestion changes the behavior?
Oct 27, 2020 at 2:07pm
Previously I've had issues with using / rather than \.
Oct 27, 2020 at 2:10pm
In C++'s standard library? Or with other Windows programs? I'd be curious to see an example of the former.
(It's totally possible that std::filesystem behaves differently, but this is the first I've heard of that)
Last edited on Oct 27, 2020 at 2:11pm
Oct 27, 2020 at 2:20pm
@seeplus,

For windows, \ is the name delimiter, not /
That is not entirely true.

I do not know what version of Windows it started in, but I do know that in Windows 10 the forward slash is legal and usable in a path.

Andy
Oct 27, 2020 at 2:24pm
So I tried to use the std::uintmax_t remove_all(const std::filesystem::path& p, std::error_code& ec); line but Visual Studio kept giving me errors.

the last / didn't matter and as far as I know nothing is misspelled.

switch / to \\ did not help.

There are 3 subfolders. One of them gets deleted no problems then the program crashes on the other 2. They have the same contents are the one deleted except there is one extra file in the one deleted and the versions are older in one of the 2 that aren't delete.
Oct 27, 2020 at 2:26pm
Another weird thing I noticed is that if I let everything sit for several minutes it then runs fine a few times then starts acting up again.
Topic archived. No new replies allowed.