How to get the path that threw UnauthorizedAccessException?

Does anyone know if you catch a UnauthorizedAccessException in C # to access the path that threw it? I do not want the error message to just cause the problem. The catch try block that I have can be captured by several different ones, but I need to report it and go to the next directory / file without adding the entire exception message.

+3
source share
2 answers

Perhaps your error handling will be more granular, so you only catch one try when it explodes? You can do this (without repeating yourself) by refactoring the code of the offensive code to a useful method - i.e.

TryCopyFile(path1);
TryCopyFile(path2);
TryCopyFile(path3);

TryCopyFile () , .

+4

Message UnauthorizedAccessException - :

Access to the path 'E:\Domains\xxx\wwwroot\Images\main.aspx' is denied.

.

+1

Source: https://habr.com/ru/post/1707780/


All Articles