Skip to content

Commit

Permalink
Catch exception when accessing Application::Current in WindowsRTPlatf…
Browse files Browse the repository at this point in the history
…ormEventHandler deconstructor like in the constructor as both have the same risk of throwing the exception (#1072)

Co-authored-by: Lalit Kumar Bhasin <[email protected]>
  • Loading branch information
j388923r and lalitb authored Dec 1, 2022
1 parent b18988f commit ddb7257
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/shared/WindowsRTPlatformEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,26 @@ namespace Microsoft {

PlatformEventHandler::~PlatformEventHandler()
{
if (this->m_suspendToken.Value != 0)
try
{
Application::Current->Suspending -= this->m_suspendToken;
}
if (this->m_suspendToken.Value != 0)
{
Application::Current->Suspending -= this->m_suspendToken;
}

if (this->m_resumeToken.Value != 0)
{
Application::Current->Resuming -= this->m_resumeToken;
}
if (this->m_resumeToken.Value != 0)
{
Application::Current->Resuming -= this->m_resumeToken;
}

if (this->m_unhandledExceptionToken.Value != 0)
if (this->m_unhandledExceptionToken.Value != 0)
{
Application::Current->UnhandledException -= this->m_unhandledExceptionToken;
}
}
catch (Exception^ e)
{
Application::Current->UnhandledException -= this->m_unhandledExceptionToken;
// Access to Application::Current can generate COM exceptions.
}
}

Expand Down

0 comments on commit ddb7257

Please sign in to comment.