Skip to content

Commit f2f08f7

Browse files
authored
Ignore errors during manual unregistration (#1005)
1 parent 8f40198 commit f2f08f7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

cppwinrt.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
1313
</PropertyGroup>
1414

15+
<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
16+
<PlatformToolset>v143</PlatformToolset>
17+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
18+
</PropertyGroup>
19+
1520
<!--
1621
Can be used as follows.
1722

cppwinrt/code_writers.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,23 @@ namespace cppwinrt
11201120

11211121
if (is_noexcept(method))
11221122
{
1123-
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
1123+
if (is_remove_overload(method))
1124+
{
1125+
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
1126+
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
1127+
{%
1128+
WINRT_IMPL_SHIM(%)->%(%);%
1129+
}
1130+
)";
1131+
}
1132+
else
1133+
{
1134+
format = R"( template <typename D%> WINRT_IMPL_AUTO(%) consume_%<D%>::%(%) const noexcept
11241135
{%
11251136
WINRT_VERIFY_(0, WINRT_IMPL_SHIM(%)->%(%));%
11261137
}
11271138
)";
1139+
}
11281140
}
11291141
else
11301142
{

test/old_tests/UnitTests/event_consume.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct TestSplashScreen : implements<TestSplashScreen, ISplashScreen>
3737
void Dismissed(event_token cookie)
3838
{
3939
m_dismissed.remove(cookie);
40+
41+
throw hresult_error(0x80010108); // this exception should always be ignored.
4042
}
4143
};
4244

@@ -61,6 +63,8 @@ struct TestClipboardStatics : implements<TestClipboardStatics, IClipboardStatics
6163
void ContentChanged(event_token token)
6264
{
6365
m_contentChanged.remove(token);
66+
67+
throw hresult_error(0x80010108); // this exception should always be ignored.
6468
}
6569
};
6670

0 commit comments

Comments
 (0)