#include "GetThrownOSStatus.h" #include #include #include //when you have a mess of multiple frameworks throwing different stuff at you //it is hard to catch all kinds of exceptions every time //so the solution is to catch them all with one catch(...) //and call GetThrownOSStatus() inside like this /* try { //do some risky stuff here } catch(...) { OSStatus myThrownError = GetThrownOSStatus(); //we've got the error code to report } */ OSStatus GetThrownOSStatus() { OSStatus outStatus = -1;//start with unknown try { throw;//re-throw to see what we can catch } catch (const OSStatus &theStatus) { outStatus = theStatus; } catch (const OSErr &theErr) { outStatus = theErr; } catch(const PP_PowerPlant::LException& theException) { outStatus = theException.GetErrorCode(); } catch(const std::exception& theStdException) { //standard exception does not offer us any error value //we can guess that in most cases it means that the operator new thrown it outStatus = memFullErr; } catch(const PPx::OSError& thePPxException) { outStatus = thePPxException.GetOSErrorCode(); } catch(...) { //unknown, stays: -1 } return outStatus; }