src/thread/stdcpp/SDL_sysmutex.cpp
changeset 8484 7258989352eb
parent 8360 7f1bc00e59fc
child 8488 bb48911cd9c8
     1.1 --- a/src/thread/stdcpp/SDL_sysmutex.cpp	Tue Aug 20 21:22:32 2013 -0400
     1.2 +++ b/src/thread/stdcpp/SDL_sysmutex.cpp	Tue Aug 20 21:54:34 2013 -0400
     1.3 @@ -26,7 +26,7 @@
     1.4  #include "SDL_log.h"
     1.5  }
     1.6  
     1.7 -#include <exception>
     1.8 +#include <system_error>
     1.9  
    1.10  #include "SDL_sysmutex_c.h"
    1.11  #include <Windows.h>
    1.12 @@ -41,11 +41,11 @@
    1.13      try {
    1.14          SDL_mutex * mutex = new SDL_mutex;
    1.15          return mutex;
    1.16 -    } catch (std::exception & ex) {
    1.17 -        SDL_SetError("unable to create C++ mutex: %s", ex.what());
    1.18 +    } catch (std::system_error & ex) {
    1.19 +        SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
    1.20          return NULL;
    1.21 -    } catch (...) {
    1.22 -        SDL_SetError("unable to create C++ mutex due to an unknown exception");
    1.23 +    } catch (std::bad_alloc &) {
    1.24 +        SDL_OutOfMemory();
    1.25          return NULL;
    1.26      }
    1.27  }
    1.28 @@ -56,11 +56,7 @@
    1.29  SDL_DestroyMutex(SDL_mutex * mutex)
    1.30  {
    1.31      if (mutex) {
    1.32 -        try {
    1.33 -            delete mutex;
    1.34 -        } catch (...) {
    1.35 -            // catch any and all exceptions, just in case something happens
    1.36 -        }
    1.37 +        delete mutex;
    1.38      }
    1.39  }
    1.40  
    1.41 @@ -79,11 +75,8 @@
    1.42      try {
    1.43          mutex->cpp_mutex.lock();
    1.44          return 0;
    1.45 -    } catch (std::exception & ex) {
    1.46 -        SDL_SetError("unable to lock C++ mutex: %s", ex.what());
    1.47 -        return -1;
    1.48 -    } catch (...) {
    1.49 -        SDL_SetError("unable to lock C++ mutex due to an unknown exception");
    1.50 +    } catch (std::system_error & ex) {
    1.51 +        SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
    1.52          return -1;
    1.53      }
    1.54  }
    1.55 @@ -100,14 +93,8 @@
    1.56          return -1;
    1.57      }
    1.58  
    1.59 -    try {
    1.60 -        mutex->cpp_mutex.unlock();
    1.61 -        return 0;
    1.62 -    } catch (...) {
    1.63 -        // catch any and all exceptions, just in case something happens.
    1.64 -        SDL_SetError("unable to unlock C++ mutex due to an unknown exception");
    1.65 -        return -1;
    1.66 -    }
    1.67 +    mutex->cpp_mutex.unlock();
    1.68 +    return 0;
    1.69  }
    1.70  
    1.71  /* vi: set ts=4 sw=4 expandtab: */