3535namespace fs = std::filesystem;
3636
3737int wmain (int argc, wchar_t * argv[])
38+ try
3839{
3940 SetConsoleOutputCP (CP_UTF8);
4041
@@ -102,10 +103,12 @@ int wmain(int argc, wchar_t* argv[])
102103 return 1 ;
103104 }
104105
105- const fs::path dllFilePath = fs::absolute (arguments.dll .value ());
106+ std::error_code ec{};
107+
108+ const fs::path dllFilePath = fs::absolute (arguments.dll .value (), ec);
106109 std::wstring labelName = arguments.label .value_or (L" " DEFAULT_LABEL);
107110
108- if (!fs::exists (dllFilePath) || !fs::is_regular_file (dllFilePath))
111+ if (!fs::exists (dllFilePath, ec ) || !fs::is_regular_file (dllFilePath, ec ))
109112 {
110113 PrintErrorLn (L" DLL file '{}' does not exist or is not readable" , dllFilePath.wstring ());
111114 return 1 ;
@@ -175,7 +178,7 @@ int wmain(int argc, wchar_t* argv[])
175178 }
176179 else
177180 {
178- pdbFilePath = fs::absolute (filePath);
181+ pdbFilePath = fs::absolute (filePath, ec );
179182 }
180183
181184#ifdef MTA_DEBUG
@@ -188,7 +191,7 @@ int wmain(int argc, wchar_t* argv[])
188191 PrintLn (L" [~] Ignore: '{}'" , ignore);
189192#endif
190193
191- if (!fs::exists (pdbFilePath) || !fs::is_regular_file (pdbFilePath))
194+ if (!fs::exists (pdbFilePath, ec ) || !fs::is_regular_file (pdbFilePath, ec ))
192195 {
193196 PrintErrorLn (L" {} is not a regular file" , pdbFilePath.wstring ());
194197 return 1 ;
@@ -281,7 +284,7 @@ int wmain(int argc, wchar_t* argv[])
281284
282285 std::vector<std::wstring> problems;
283286
284- if (!hasLabel && !fs::is_regular_file (function.SourceFile ))
287+ if (!hasLabel && !fs::is_regular_file (function.SourceFile , ec ))
285288 continue ;
286289
287290 if (function.Name .starts_with (L" std::" ) || function.Name .starts_with (L' _' ))
@@ -336,3 +339,27 @@ int wmain(int argc, wchar_t* argv[])
336339
337340 return exitCode;
338341}
342+ catch (const fs::filesystem_error& ex)
343+ {
344+ HRESULT hr = S_OK;
345+
346+ if (ex.code ())
347+ {
348+ if (ex.code ().category () == std::system_category ())
349+ {
350+ hr = HRESULT_FROM_WIN32 (ex.code ().value ());
351+ }
352+ else
353+ {
354+ hr = E_FAIL;
355+ }
356+ }
357+
358+ PrintErrorLn (hr, L" A filesystem exception was thrown: {}" , ToWideString (ex.what ()));
359+ return -1 ;
360+ }
361+ catch (const std::exception& ex)
362+ {
363+ PrintErrorLn (L" An exception was thrown: {}" , ToWideString (ex.what ()));
364+ return -1 ;
365+ }
0 commit comments