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.1 --- a/src/thread/stdcpp/SDL_syscond.cpp Tue Aug 20 21:22:32 2013 -0400
1.2 +++ b/src/thread/stdcpp/SDL_syscond.cpp Tue Aug 20 21:54:34 2013 -0400
1.3 @@ -26,8 +26,8 @@
1.4
1.5 #include <chrono>
1.6 #include <condition_variable>
1.7 -#include <exception>
1.8 #include <ratio>
1.9 +#include <system_error>
1.10
1.11 #include "SDL_sysmutex_c.h"
1.12
1.13 @@ -45,11 +45,11 @@
1.14 try {
1.15 SDL_cond * cond = new SDL_cond;
1.16 return cond;
1.17 - } catch (std::exception & ex) {
1.18 - SDL_SetError("unable to create C++ condition variable: %s", ex.what());
1.19 + } catch (std::system_error & ex) {
1.20 + SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
1.21 return NULL;
1.22 - } catch (...) {
1.23 - SDL_SetError("unable to create C++ condition variable due to an unknown exception");
1.24 + } catch (std::bad_alloc &) {
1.25 + SDL_OutOfMemory();
1.26 return NULL;
1.27 }
1.28 }
1.29 @@ -60,11 +60,7 @@
1.30 SDL_DestroyCond(SDL_cond * cond)
1.31 {
1.32 if (cond) {
1.33 - try {
1.34 - delete cond;
1.35 - } catch (...) {
1.36 - // catch any and all exceptions, just in case something happens
1.37 - }
1.38 + delete cond;
1.39 }
1.40 }
1.41
1.42 @@ -78,14 +74,8 @@
1.43 return -1;
1.44 }
1.45
1.46 - try {
1.47 - cond->cpp_cond.notify_one();
1.48 - return 0;
1.49 - } catch (...) {
1.50 - // catch any and all exceptions, just in case something happens
1.51 - SDL_SetError("unable to signal C++ condition variable due to an unknown exception");
1.52 - return -1;
1.53 - }
1.54 + cond->cpp_cond.notify_one();
1.55 + return 0;
1.56 }
1.57
1.58 /* Restart all threads that are waiting on the condition variable */
1.59 @@ -98,14 +88,8 @@
1.60 return -1;
1.61 }
1.62
1.63 - try {
1.64 - cond->cpp_cond.notify_all();
1.65 - return 0;
1.66 - } catch (...) {
1.67 - // catch any and all exceptions, just in case something happens
1.68 - SDL_SetError("unable to broadcast C++ condition variable due to an unknown exception");
1.69 - return -1;
1.70 - }
1.71 + cond->cpp_cond.notify_all();
1.72 + return 0;
1.73 }
1.74
1.75 /* Wait on the condition variable for at most 'ms' milliseconds.
1.76 @@ -163,11 +147,8 @@
1.77 return 0;
1.78 }
1.79 }
1.80 - } catch (std::exception & ex) {
1.81 - SDL_SetError("unable to wait on C++ condition variable: %s", ex.what());
1.82 - return -1;
1.83 - } catch (...) {
1.84 - SDL_SetError("unable to lock wait on C++ condition variable due to an unknown exception");
1.85 + } catch (std::system_error & ex) {
1.86 + SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
1.87 return -1;
1.88 }
1.89 }
2.1 --- a/src/thread/stdcpp/SDL_sysmutex.cpp Tue Aug 20 21:22:32 2013 -0400
2.2 +++ b/src/thread/stdcpp/SDL_sysmutex.cpp Tue Aug 20 21:54:34 2013 -0400
2.3 @@ -26,7 +26,7 @@
2.4 #include "SDL_log.h"
2.5 }
2.6
2.7 -#include <exception>
2.8 +#include <system_error>
2.9
2.10 #include "SDL_sysmutex_c.h"
2.11 #include <Windows.h>
2.12 @@ -41,11 +41,11 @@
2.13 try {
2.14 SDL_mutex * mutex = new SDL_mutex;
2.15 return mutex;
2.16 - } catch (std::exception & ex) {
2.17 - SDL_SetError("unable to create C++ mutex: %s", ex.what());
2.18 + } catch (std::system_error & ex) {
2.19 + SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
2.20 return NULL;
2.21 - } catch (...) {
2.22 - SDL_SetError("unable to create C++ mutex due to an unknown exception");
2.23 + } catch (std::bad_alloc &) {
2.24 + SDL_OutOfMemory();
2.25 return NULL;
2.26 }
2.27 }
2.28 @@ -56,11 +56,7 @@
2.29 SDL_DestroyMutex(SDL_mutex * mutex)
2.30 {
2.31 if (mutex) {
2.32 - try {
2.33 - delete mutex;
2.34 - } catch (...) {
2.35 - // catch any and all exceptions, just in case something happens
2.36 - }
2.37 + delete mutex;
2.38 }
2.39 }
2.40
2.41 @@ -79,11 +75,8 @@
2.42 try {
2.43 mutex->cpp_mutex.lock();
2.44 return 0;
2.45 - } catch (std::exception & ex) {
2.46 - SDL_SetError("unable to lock C++ mutex: %s", ex.what());
2.47 - return -1;
2.48 - } catch (...) {
2.49 - SDL_SetError("unable to lock C++ mutex due to an unknown exception");
2.50 + } catch (std::system_error & ex) {
2.51 + SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
2.52 return -1;
2.53 }
2.54 }
2.55 @@ -100,14 +93,8 @@
2.56 return -1;
2.57 }
2.58
2.59 - try {
2.60 - mutex->cpp_mutex.unlock();
2.61 - return 0;
2.62 - } catch (...) {
2.63 - // catch any and all exceptions, just in case something happens.
2.64 - SDL_SetError("unable to unlock C++ mutex due to an unknown exception");
2.65 - return -1;
2.66 - }
2.67 + mutex->cpp_mutex.unlock();
2.68 + return 0;
2.69 }
2.70
2.71 /* vi: set ts=4 sw=4 expandtab: */
3.1 --- a/src/thread/stdcpp/SDL_systhread.cpp Tue Aug 20 21:22:32 2013 -0400
3.2 +++ b/src/thread/stdcpp/SDL_systhread.cpp Tue Aug 20 21:54:34 2013 -0400
3.3 @@ -31,6 +31,7 @@
3.4
3.5 #include <mutex>
3.6 #include <thread>
3.7 +#include <system_error>
3.8
3.9 // HACK: Mimic C++11's thread_local keyword on Visual C++ 2012 (aka. VC++ 11)
3.10 // TODO: make sure this hack doesn't get used if and when Visual C++ supports
3.11 @@ -55,11 +56,11 @@
3.12 std::thread cpp_thread(RunThread, args);
3.13 thread->handle = (void *) new std::thread(std::move(cpp_thread));
3.14 return 0;
3.15 - } catch (std::exception & ex) {
3.16 - SDL_SetError("unable to create a C++ thread: %s", ex.what());
3.17 + } catch (std::system_error & ex) {
3.18 + SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
3.19 return -1;
3.20 - } catch (...) {
3.21 - SDL_SetError("unable to create a C++ thread due to an unknown exception");
3.22 + } catch (std::bad_alloc &) {
3.23 + SDL_OutOfMemory();
3.24 return -1;
3.25 }
3.26 }
3.27 @@ -114,10 +115,10 @@
3.28 if (cpp_thread->joinable()) {
3.29 cpp_thread->join();
3.30 }
3.31 - } catch (...) {
3.32 - // Catch any exceptions, just in case.
3.33 - // Report nothing, as SDL_WaitThread does not seem to offer a means
3.34 - // to report errors to its callers.
3.35 + } catch (std::system_error &) {
3.36 + // An error occurred when joining the thread. SDL_WaitThread does not,
3.37 + // however, seem to provide a means to report errors to its callers
3.38 + // though!
3.39 }
3.40 }
3.41