Professional Development – 2024 – Week 16

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

.NET 9 Fixed Exceptions but Still Don’t Use Them (via Nick Chapas)

  • Although .NET 9 Preview 3 has made exceptions 2-4x faster, using exceptions for business domain things (e.g., email already in use when creating a new account, validation errors) is still not performant. Exceptions are expensive in terms of time and memory because of the extra overhead to capture context.
  • One solution is to use the OneOf type (NuGet package) to implement a discriminated union return type. For example, OneOf<int, object> where if things go well, the int has the value.