dotnet
dotnet copied to clipboard
Add ThrowEndOfStreamException and ThrowHttpRequestException to ThrowHelpers
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