Skip to content
0:00 / 0:00

#resultpattern#errorhandling#exceptions

Get Rid of Exceptions in Your Code With the Result Pattern

Milan Jovanović

169K subscribers • 11 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Milan Jovanović
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

79K views2 years ago2 recommendations

Software designProgramming languagesC# and .NETDesign patternsFunctional programming

Milan Jovanović compares throwing exceptions with returning a Result object for domain validation, showing how to implement the Result pattern in C#.

Get the source code for this video for FREE → the-dotnet-weekly.ck.page/result-pattern ☄️ Master the Modular Monolith Architecture: bit.ly/3SXlzSt 📌 Accelerate your Clean Architecture skills: bit.ly/3PupkOJ 🚀 Support me on Patreon to access the source code: patreon.com/milanjovanovic I will show you two approaches for Domain validation with .NET. The first approach will be based on throwing exceptions. The second approach will be based on returning a result object. I'll show you how to extend the Result pattern with errors and clean up your design. It's more performant and expressive than throwing exceptions. Which validation approach would you choose? I prefer expressing errors using the Result pattern. Join my weekly .NET newsletter: milanjovanovic.tech Read my Blog here: milanjovanovic.tech/blog Chapters Why I don't prefer throwing exceptions Returning error messages instead of throwing exceptions Adding an Error type express errors in the domain Documenting domain errors for a better design Using a Result object to represent success or failure

Why it's here

2 people recommend this

What people say. Recommended for learning how to implement the Result pattern to handle errors cleanly without throwing exceptions.

u/INN_Ginein r/dotnet • Recommends

On “Is there a modern best practice for return types?”

Currently I have no access to my projects but I recommend this youtube channel it teaches a lot: [video Specifically this video can teach you about MediatR pipelines: [video This one about Result pattern: [video Also here is Some microsoft documentation about problem details: https://learn.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-8.0#problem-details-service

u/blazor_tazorin r/dotnet • Recommends

On “How can I return a 404 error from a service in ASP.NET Core?”

> But somehow the service must do something to indicate, that the request was bad. Sometimes returning "null" is enough, other times you want more detail. You can use the result pattern for this. That means that you can return different errors based on what went wrong. You can then also create an extension/mapper that takes in the result object and maps it to the proper httpresult: Example from youtube: link to this video Example of nuget package that returns "ErrorOr<OptionalSuccessModelHere> " https://github.com/amantinband/error-or