DEV Community

Discussion on: Error handling and validation architecture in .NET Core

Collapse
 
boriszn profile image
Boris Zaikin

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 ? ;)

Collapse
 
silverferrum profile image
Nik S

Hi!
Validation exceptions are what Microsoft does not recommend to do.
docs.microsoft.com/en-us/visualstu...

Thread Thread
 
boriszn profile image
Boris Zaikin

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...

Thread Thread
 
silverferrum profile image
Nik S • Edited

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...