stlab.adobe.com Adobe Systems Incorporated

macintosh_error.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /****************************************************************************************************/
00008 
00009 #ifndef ADOBE_MACINTOSH_ERROR_HPP
00010 #define ADOBE_MACINTOSH_ERROR_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/macintosh_carbon_safe.hpp>
00015 
00016 #include <boost/function.hpp>
00017 
00018 #include <sstream>
00019 #include <stdexcept>
00020 
00021 /****************************************************************************************************/
00022 
00023 namespace adobe {
00024 
00025 /*************************************************************************************************/
00026 
00027 class os_exception : public std::exception
00028 {
00029 public:
00030     os_exception(long status, const char* file, long line) throw()
00031     {
00032         try
00033         {
00034             std::stringstream t;
00035             t << status;
00036             format(t.str().c_str(), file, line);
00037         }
00038         catch (...)
00039         { }
00040     }
00041 
00042     os_exception(const char* status, const char* file, long line) throw()
00043     {
00044         format(status, file, line);
00045     }
00046 
00047     os_exception(const std::string& status, const char* file, long line) throw()
00048     {
00049         format(status.c_str(), file, line);
00050     }
00051 
00052     ~os_exception() throw() {}
00053 
00054     const char* what () const throw()
00055     { return what_m.c_str(); }
00056 
00057 private:
00058 
00059     void format(const char* status, const char* file, long line)
00060     {
00061         try
00062         {
00063             std::stringstream t;
00064             t << "Error: " << status << " (" << file << ", line " << line << ")";
00065             what_m.assign(t.str());
00066         }
00067         catch (...)
00068         { }
00069     }
00070 
00071     std::string what_m;
00072 };
00073 
00074 /****************************************************************************************************/
00075 
00076 typedef boost::function<void (std::string)> error_handler_proc_t;
00077 
00078 //
00086 //
00087 
00088 void set_error_handler(const error_handler_proc_t& proc);
00089 
00090 //
00094 //
00095 
00096 void report_error(const std::string& error);
00097 
00098 /****************************************************************************************************/
00099 
00100 namespace implementation {
00101 
00102 /*************************************************************************************************/
00103 
00104 inline void ADOBE_REQUIRE_STATUS_impl(long status, const char* file, long line)
00105 {
00106 //    if (status != 0)
00107 //        ::AudioServicesPlayAlertSound(kUserPreferredAlert);
00108 
00109     // REVISIT (fbrereto) : Turn this back on when we have an interface to handle
00110     //                      errors on the callback side of the OS event loop
00111     return;
00112 
00113     if (status != 0)
00114         throw os_exception(status, file, line);
00115 }
00116 
00117 /*************************************************************************************************/
00118 
00119 #define ADOBE_REQUIRE_STATUS(x) adobe::implementation::ADOBE_REQUIRE_STATUS_impl((x), __FILE__, __LINE__)
00120 
00121 /****************************************************************************************************/
00122 
00123 } // namespace implementation
00124 
00125 /****************************************************************************************************/
00126 
00127 } // namespace adobe
00128 
00129 /****************************************************************************************************/
00130 
00131 #endif
00132 
00133 /****************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google