Skip to content

Commit

Permalink
Ignore errors during manual unregistration (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylveon authored Aug 25, 2021
1 parent 8f40198 commit f2f08f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cppwinrt.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
<PlatformToolset>v143</PlatformToolset>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>

<!--
Can be used as follows.
Expand Down
14 changes: 13 additions & 1 deletion cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,23 @@ namespace cppwinrt

if (is_noexcept(method))
{
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
if (is_remove_overload(method))
{
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
{%
WINRT_IMPL_SHIM(%)->%(%);%
}
)";
}
else
{
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
{%
WINRT_VERIFY_(0, WINRT_IMPL_SHIM(%)->%(%));%
}
)";
}
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions test/old_tests/UnitTests/event_consume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct TestSplashScreen : implements<TestSplashScreen, ISplashScreen>
void Dismissed(event_token cookie)
{
m_dismissed.remove(cookie);

throw hresult_error(0x80010108); // this exception should always be ignored.
}
};

Expand All @@ -61,6 +63,8 @@ struct TestClipboardStatics : implements<TestClipboardStatics, IClipboardStatics
void ContentChanged(event_token token)
{
m_contentChanged.remove(token);

throw hresult_error(0x80010108); // this exception should always be ignored.
}
};

Expand Down

0 comments on commit f2f08f7

Please sign in to comment.