dotnet / dotnet/docs

Are throw helpers really more efficient?

Open
#42,805 2 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

### Type of issue

Typo

### Description

From https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8/sdk#code-analysis

> Throw helpers are simpler **and more efficient** than an if block constructing a new exception instance.

Having look at https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Private.CoreLib/src/System/ArgumentNullException.cs, I see that in order to throw 2 methods are called and no optimization which could be more efficient than simple `if`-then construct.

### Page URL

https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8/sdk

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/whats-new/dotnet-8/sdk.md

### Document Version Independent Id

2dd1bc19-cfa0-3d7d-4931-1f0f4fefac12

### Article author

@gewarren

### Metadata

* ID: 0b25da3d-7bbf-d16d-3caf-e56923fe9716
* Service: **dotnet-fundamentals**

[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+2dd1bc19-cfa0-3d7d-4931-1f0f4fefac12)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.