You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently The setter on Exception.HResult is protected. If customer need to set a different HResult for a specific exception, customer has to create a derived exception to override.
Rationale and Usage
It is very common to set a different HResult for interop area due to compatibility reason --- Interop should return same HResult as the code is called/implemented by native code.
Exception.SetErrorCode is an internal API. The HResult for ObjectDisposedException is 0x80131622 and RO_E_CLOSED is 0x80000013
if (_fClosed)
{
return RO_E_CLOSED;
}
With this change, you can directly assign HResult and remove SetErrorCode internal API.
ex. HResult = __HResults.RO_E_CLOSED;
Proposed API
publicpartialclassException: System.Runtime.Serialization.ISerializable
{// Existing members// public int HResult { get { throw null; } protected set { } }// Proposed memberspublicintHResult{get{thrownull;}set{}}}
Details
There are other ways to achieve this:
Change Exception.SetErrorCode from Internal to public API
Pro: a lot of existing code already use this API, less code change
Con: More complicated than proposed one. There are two ways to change HResult(Derived from exists exception and use Exception.SetErrorCode API).
Add a new public API in Marshal which update HResult for an exception
Pro: It works
Con: Complicated and customer have to know this new Marshal API exists.
Overall, Make Exception.HResult setter to public is simpler way to do this.
The text was updated successfully, but these errors were encountered:
Currently The setter on Exception.HResult is protected. If customer need to set a different HResult for a specific exception, customer has to create a derived exception to override.
Rationale and Usage
It is very common to set a different HResult for interop area due to compatibility reason --- Interop should return same HResult as the code is called/implemented by native code.
For example:
https://github.com/dotnet/corefx/blob/02a26f8f417967e31bab8d96605d3d8846154e8a/src/System.Runtime.WindowsRuntime/src/System/IO/NetFxToWinRtStreamAdapter.cs#L195
Exception.SetErrorCode is an internal API. The HResult for ObjectDisposedException is 0x80131622 and RO_E_CLOSED is 0x80000013
With this change, you can directly assign HResult and remove SetErrorCode internal API.
Proposed API
Details
There are other ways to achieve this:
Overall, Make Exception.HResult setter to public is simpler way to do this.
The text was updated successfully, but these errors were encountered: