CommunityToolkit / CommunityToolkit/dotnet

Add ThrowEndOfStreamException and ThrowHttpRequestException to ThrowHelpers

Open
#255 0 comments 1 reaction 0 assignees View on GitHub
feature request :mailbox_with_mail:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Overview

ThrowHelpers does not have methods to throw EndOfStreamException or HttpRequestException so I think they should be added.

### API breakdown

```csharp
[DoesNotReturn]
public static void ThrowEndOfStreamException()
{
throw new EndOfStreamException();
}
```
```csharp
[DoesNotReturn]
public static void ThrowHttpRequestException()
{
throw new HttpRequestException();
}
```
And all the other overloads and generic verisons.

### Usage example

```csharp
int read = stream.Read(buffer);
if (read == 0)
{
ThrowHelpers.ThrowEndOfStreamException();
}
```

```csharp
HttpResponseMessage response = ... ;
if (response.StatusCode != HttpStatusCode.PartialContent)
{
ThrowHelpers.ThrowHttpRequestException($"Response body status code was expected to be {HttpStatusCode.PartialContent} but was {response.StatusCode} instead.");
}
```

### Breaking change?

No

### Alternatives

The alternative would be to write these functions manually in any project they would need to be used in.

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item

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.