dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Add ThrowEndOfStreamException and ThrowHttpRequestException to ThrowHelpers

Open Xpl0itR opened this issue 3 years ago • 0 comments

Overview

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

API breakdown

[DoesNotReturn]
public static void ThrowEndOfStreamException()
{
    throw new EndOfStreamException();
}
[DoesNotReturn]
public static void ThrowHttpRequestException()
{
    throw new HttpRequestException();
}

And all the other overloads and generic verisons.

Usage example

int read = stream.Read(buffer);
if (read == 0)
{
    ThrowHelpers.ThrowEndOfStreamException();
}
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

Xpl0itR avatar May 15 '22 03:05 Xpl0itR