© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
43 replies
peladococinero

The best way to handle Errors in Clean Arch

Hello, everything okay? I have a question. I want to know what is the best way to handle errors in my application using Clean Architecture. To put you in context, I am creating a layered API, that is, there is the Infrastructure that contains the repository and the application layer that contains the service. The logic goes in the service, for example, when a user registers and their username has at least 6 characters, then it throws an error that is ArgumentException with a message:
throw new ArgumentException("The Password must be at least 6 characters");
throw new ArgumentException("The Password must be at least 6 characters");


Now, in the controller, what is the best way to handle those errors? Why does it always return a status code of 500, while the error could be 401? Also, how do I resolve the message? Thank you so much. I leave you images so that you can put yourself in context.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ the best way to clean up SqlConnection
C#CC# / help
3y ago
How to best manage DTOs in Clean arch DDD project
C#CC# / help
12mo ago
Localization in Clean Architectire
C#CC# / help
7mo ago
What the best way to handle splines/rail grinding in Unity?
C#CC# / help
17mo ago