Exceptions Are Extremely Expensive… Do This Instead

Author: Milan Jovanović
Published At: 2024-07-12T00:00:00
Length: 17:15

Summary

Description

Want to master Clean Architecture? Go here: https://bit.ly/3PupkOJ

Want to unlock Modular Monoliths? Go here: https://bit.ly/3SXlzSt

Join a community of 1000+ .NET developers: https://www.patreon.com/milanjovanovic

How should you handle errors in your code? This has been a topic of many discussions, and I want to share my opinion. One school of thought suggests using exceptions for flow control. This is not a good approach because it makes the code harder to reason about. The caller must know the implementation details and which exceptions to handle. Exceptions are for exceptional situations. Exceptions are also costly and degrade performance. If you don't believe me, we'll prove it in this video.

GitHub thread: https://github.com/dotnet/aspnetcore/issues/46280#issuecomment-1527898867

Functional Error Handling in .NET With the Result Pattern

https://www.milanjovanovic.tech/blog/functional-error-handling-in-dotnet-with-the-result-pattern

Check out my courses:

https://www.milanjovanovic.tech/courses

Read my Blog here:

https://www.milanjovanovic.tech/blog

Join my weekly .NET newsletter:

https://www.milanjovanovic.tech

Chapters

0:00 Are exceptions expensive?

3:14 Exceptions for flow control

7:38 Performance testing exceptions

10:23 Handling errors with Result pattern

14:11 Performance testing Result pattern

15:30 Result pattern drawbacks

Translated At: 2025-03-13T17:20:19Z

Request translate (One translation is about 5 minutes)

Version 3 (stable)

Optimized for a single speaker. Suitable for knowledge sharing or teaching videos.

Recommended Videos