[Feature] ThrowHelper APIs with return values #3454
Labels
Completed 🔥
feature request 📬
A request for new changes to improve functionality
.NET
Components which are .NET based (non UWP specific)
Milestone
Describe the problem this feature would solve
The new
ThrowHelper
APIs added in #3346 currently can't be used within switch statements or in cases where users need a return value from the invoked API in order to make the C# compiler happy. Consider this sample:That
throw
can't be replaced with aThrowHelper
call, as they all returnvoid
. This forces users to either manually write a throw function, which is verbose and defeats the whole point of having theThrowHelper
APIs, or to leave the exception there and get terrible codegen, which again defeats the whole point of worrying about this in the first place.Describe the solution
We should also offer overloads of all the
ThrowHelper
APIs with a dummyT
return, so that devs can use them in cases like this.The above example would become as follows:
Which produces a very nice codegen:
Describe alternatives you've considered
Additional context & Screenshots
Full sharplab.io sample here.
The text was updated successfully, but these errors were encountered: