Isn't it a bad practice to throw validation exceptions? I mean, we would expect to receive some invalid user input data, it's not an exceptional situation.
Hey Marcell. Thank you for you comment. Exceptions allows you to gather all validation errors and intersect it in the meedle-ware. Moreover this concept used in many libraries, including .NET Core, Swagger etc. This is better than constantly repeat if-else (Crossing DRY principle) And why validation error can't be an exception ? And what is exception then ? ;)
Well, this document is outdated (since 11/04/2016) moreover it is for .NET Framework. In the Dot Net Core things work slightly different ;)
Here is some example: docs.microsoft.com/en-us/aspnet/co...
Isn't it a bad practice to throw validation exceptions? I mean, we would expect to receive some invalid user input data, it's not an exceptional situation.
Hey Marcell. Thank you for you comment. Exceptions allows you to gather all validation errors and intersect it in the meedle-ware. Moreover this concept used in many libraries, including .NET Core, Swagger etc. This is better than constantly repeat if-else (Crossing DRY principle) And why validation error can't be an exception ? And what is exception then ? ;)
Hi!
Validation exceptions are what Microsoft does not recommend to do.
docs.microsoft.com/en-us/visualstu...
Hey,
Well, this document is outdated (since 11/04/2016) moreover it is for .NET Framework. In the Dot Net Core things work slightly different ;)
Here is some example: docs.microsoft.com/en-us/aspnet/co...
Below on that page "Validation failure error response",
docs.microsoft.com/en-us/aspnet/co...
In addition "Model validation in ASP.NET Core MVC and Razor Pages",
docs.microsoft.com/en-us/aspnet/co...
"ASP.NET Core Performance Best Practices: Minimize exceptions"
docs.microsoft.com/ru-ru/aspnet/co...