-
Notifications
You must be signed in to change notification settings - Fork 1.4k
ThrowHelper APIs #3346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThrowHelper APIs #3346
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This reverts commit f70ae0c. Unfortunately the attribute is actually matched by type and not just by name like the others. We should reintroduce this once either dotnet/runtime#29681 is done, or when the runtime switches to a name matching for the internal attribute, so we can just use a local copy here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions more around organization of the code than anything else?
Are there existing unit tests for this? Is that basically by proxy through the Guard API? Should we have a few that our specific to this new public API?
Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs
Outdated
Show resolved
Hide resolved
Moved to related HighPerformance PR
Thanks for reviewing @john-h-k! |
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> ## Follow up for #3346 and #3455 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> - Feature <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> The `ThrowHelper` class exposes static throw-helper APIs that mirror the existing constructor for all the supported exception types. In the previous PRs though I had missed the parameterless constructors, so there were no APIs for that in the `ThrowHelper` class. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> `ThrowHelper` now exposes a parameterless overload for all the supported exception types that are exposed. ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~ - [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~ - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)~~ - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes
Feature: new
ThrowHelper
APIsPR Type
What kind of change does this PR introduce?
What is the current behavior?
The
Microsoft.Toolkit.Diagnostics
namespace exposes noThrowHelper
APIs. These are useful in situations where the user can't just invoke one of theGuard
APIs to perform a check, but it might still be better to have a high performance API to delegate the exception throw operation to.This is because the throw helper pattern allows the JIT compiler to see the exception in the faulting branch, and assume that branch is always not taken. This results in better codegen both because of this, and because the actual code to instantiate the exception object is done in a method that never inlined.
What is the new behavior?
The
ThrowHelper
class is now public, with a series of throw helper APIs.All the
Guard
-specific helpers are still just internal.This PR introduce helper methods to throw the following exception types:
ArrayTypeMismatchException
ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
ExternalException
FormatException
InsufficientMemoryException
InvalidDataException
InvalidOperationException
LockRecursionException
MissingFieldException
MissingMemberException
MissingMethodException
NotSupportedException
ObjectDisposedException
OperationCanceledException
PlatformNotSupportedException
SynchronizationLockException
TimeoutException
UnauthorizedAccessException
Win32Exception
PR Checklist
Please check if your PR fulfills the following requirements:
Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templates