Why I stopped using exceptions for control flow in my .NET 8 APIs

Why I stopped using exceptions for control flow in my .NET 8 APIs For a long time, my .NET APIs looked like this: public async Task<Product> GetByIdAsync(string id) { var product = await _collection.Find(x => x.Id == id).FirstOrDefaultAsync(); if (product is null) throw new KeyNotFoundException($"Product with id '{id}' was not found."); return product; } And in the endpoint: app.MapGet("/api/products/{id}", async (string id, IProductRepository repo) =...

Original Source

Read the full article at Dev →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.