WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
diff --git a/src/thread/stdcpp/SDL_syscond.cpp b/src/thread/stdcpp/SDL_syscond.cpp
index 4ca1d96..a355607 100644
--- a/src/thread/stdcpp/SDL_syscond.cpp
+++ b/src/thread/stdcpp/SDL_syscond.cpp
@@ -26,8 +26,8 @@ extern "C" {
#include <chrono>
#include <condition_variable>
-#include <exception>
#include <ratio>
+#include <system_error>
#include "SDL_sysmutex_c.h"
@@ -45,11 +45,11 @@ SDL_CreateCond(void)
try {
SDL_cond * cond = new SDL_cond;
return cond;
- } catch (std::exception & ex) {
- SDL_SetError("unable to create C++ condition variable: %s", ex.what());
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
return NULL;
- } catch (...) {
- SDL_SetError("unable to create C++ condition variable due to an unknown exception");
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
return NULL;
}
}
@@ -60,11 +60,7 @@ void
SDL_DestroyCond(SDL_cond * cond)
{
if (cond) {
- try {
- delete cond;
- } catch (...) {
- // catch any and all exceptions, just in case something happens
- }
+ delete cond;
}
}
@@ -78,14 +74,8 @@ SDL_CondSignal(SDL_cond * cond)
return -1;
}
- try {
- cond->cpp_cond.notify_one();
- return 0;
- } catch (...) {
- // catch any and all exceptions, just in case something happens
- SDL_SetError("unable to signal C++ condition variable due to an unknown exception");
- return -1;
- }
+ cond->cpp_cond.notify_one();
+ return 0;
}
/* Restart all threads that are waiting on the condition variable */
@@ -98,14 +88,8 @@ SDL_CondBroadcast(SDL_cond * cond)
return -1;
}
- try {
- cond->cpp_cond.notify_all();
- return 0;
- } catch (...) {
- // catch any and all exceptions, just in case something happens
- SDL_SetError("unable to broadcast C++ condition variable due to an unknown exception");
- return -1;
- }
+ cond->cpp_cond.notify_all();
+ return 0;
}
/* Wait on the condition variable for at most 'ms' milliseconds.
@@ -163,11 +147,8 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
return 0;
}
}
- } catch (std::exception & ex) {
- SDL_SetError("unable to wait on C++ condition variable: %s", ex.what());
- return -1;
- } catch (...) {
- SDL_SetError("unable to lock wait on C++ condition variable due to an unknown exception");
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
return -1;
}
}
diff --git a/src/thread/stdcpp/SDL_sysmutex.cpp b/src/thread/stdcpp/SDL_sysmutex.cpp
index e43b255..df91a0d 100644
--- a/src/thread/stdcpp/SDL_sysmutex.cpp
+++ b/src/thread/stdcpp/SDL_sysmutex.cpp
@@ -26,7 +26,7 @@ extern "C" {
#include "SDL_log.h"
}
-#include <exception>
+#include <system_error>
#include "SDL_sysmutex_c.h"
#include <Windows.h>
@@ -41,11 +41,11 @@ SDL_CreateMutex(void)
try {
SDL_mutex * mutex = new SDL_mutex;
return mutex;
- } catch (std::exception & ex) {
- SDL_SetError("unable to create C++ mutex: %s", ex.what());
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
return NULL;
- } catch (...) {
- SDL_SetError("unable to create C++ mutex due to an unknown exception");
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
return NULL;
}
}
@@ -56,11 +56,7 @@ void
SDL_DestroyMutex(SDL_mutex * mutex)
{
if (mutex) {
- try {
- delete mutex;
- } catch (...) {
- // catch any and all exceptions, just in case something happens
- }
+ delete mutex;
}
}
@@ -79,11 +75,8 @@ SDL_mutexP(SDL_mutex * mutex)
try {
mutex->cpp_mutex.lock();
return 0;
- } catch (std::exception & ex) {
- SDL_SetError("unable to lock C++ mutex: %s", ex.what());
- return -1;
- } catch (...) {
- SDL_SetError("unable to lock C++ mutex due to an unknown exception");
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
return -1;
}
}
@@ -100,14 +93,8 @@ SDL_mutexV(SDL_mutex * mutex)
return -1;
}
- try {
- mutex->cpp_mutex.unlock();
- return 0;
- } catch (...) {
- // catch any and all exceptions, just in case something happens.
- SDL_SetError("unable to unlock C++ mutex due to an unknown exception");
- return -1;
- }
+ mutex->cpp_mutex.unlock();
+ return 0;
}
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/thread/stdcpp/SDL_systhread.cpp b/src/thread/stdcpp/SDL_systhread.cpp
index fb1ca31..b9252e7 100644
--- a/src/thread/stdcpp/SDL_systhread.cpp
+++ b/src/thread/stdcpp/SDL_systhread.cpp
@@ -31,6 +31,7 @@ extern "C" {
#include <mutex>
#include <thread>
+#include <system_error>
// HACK: Mimic C++11's thread_local keyword on Visual C++ 2012 (aka. VC++ 11)
// TODO: make sure this hack doesn't get used if and when Visual C++ supports
@@ -55,11 +56,11 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
std::thread cpp_thread(RunThread, args);
thread->handle = (void *) new std::thread(std::move(cpp_thread));
return 0;
- } catch (std::exception & ex) {
- SDL_SetError("unable to create a C++ thread: %s", ex.what());
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
return -1;
- } catch (...) {
- SDL_SetError("unable to create a C++ thread due to an unknown exception");
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
return -1;
}
}
@@ -114,10 +115,10 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
if (cpp_thread->joinable()) {
cpp_thread->join();
}
- } catch (...) {
- // Catch any exceptions, just in case.
- // Report nothing, as SDL_WaitThread does not seem to offer a means
- // to report errors to its callers.
+ } catch (std::system_error &) {
+ // An error occurred when joining the thread. SDL_WaitThread does not,
+ // however, seem to provide a means to report errors to its callers
+ // though!
}
}