Skip to content

Don't catch all exceptions in Directory.CreateDirectory example #11274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025

Conversation

adamsitnik
Copy link
Member

Summary

The CreateDirectory can fail with few exceptions:

  • ArgumentException, ArgumentNullException, PathTooLongException, DirectoryNotFoundException or NotSupportedException when the path is invalid
  • UnauthorizedAccessException when the caller does not have the required permission.

Since this example uses a harcoded, short and valid path c:\MyDir there is no need to catch any other exceptions than UnauthorizedAccessException

Fixes #11240

@adamsitnik adamsitnik requested a review from a team as a code owner May 6, 2025 09:39
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adamsitnik

This looks great, and I'll :shipit: now.

@BillWagner BillWagner merged commit 932893c into main May 6, 2025
6 checks passed
@BillWagner BillWagner deleted the adamsitnik-issue-11240 branch May 6, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UUF] Don't catch all exceptions
2 participants