Skip to content

Commit 47d4cd3

Browse files
committed
QuickWindowsHack
use try {} catch() {}
1 parent bf27e93 commit 47d4cd3

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

asio/include/asio/detail/impl/win_mutex.ipp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int win_mutex::do_init()
5252
# endif
5353
return 0;
5454
#else
55-
__try
55+
try
5656
{
5757
# if defined(UNDER_CE)
5858
::InitializeCriticalSection(&crit_section_);
@@ -64,10 +64,11 @@ int win_mutex::do_init()
6464
return ::GetLastError();
6565
# endif
6666
}
67-
__except(GetExceptionCode() == STATUS_NO_MEMORY
68-
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
67+
catch (const std::bad_alloc&)
6968
{
70-
return ERROR_OUTOFMEMORY;
69+
if(GetExceptionCode() == STATUS_NO_MEMORY
70+
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
71+
return ERROR_OUTOFMEMORY;
7172
}
7273

7374
return 0;

asio/include/asio/detail/impl/win_static_mutex.ipp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int win_static_mutex::do_init()
8989
}
9090
# endif
9191
#else
92-
__try
92+
try
9393
{
9494
# if defined(UNDER_CE)
9595
::InitializeCriticalSection(&crit_section_);
@@ -111,12 +111,15 @@ int win_static_mutex::do_init()
111111
}
112112
# endif
113113
}
114-
__except(GetExceptionCode() == STATUS_NO_MEMORY
115-
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
114+
catch (const std::bad_alloc&)
116115
{
117-
::ReleaseMutex(mutex);
118-
::CloseHandle(mutex);
119-
return ERROR_OUTOFMEMORY;
116+
if(GetExceptionCode() == STATUS_NO_MEMORY
117+
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
118+
{
119+
::ReleaseMutex(mutex);
120+
::CloseHandle(mutex);
121+
return ERROR_OUTOFMEMORY;
122+
}
120123
}
121124
#endif
122125

0 commit comments

Comments
 (0)