macintosh_error.hppGo to the documentation of this file.00001
00002
00003
00004
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, char* file, long line)
00105 {
00106
00107
00108
00109
00110
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 }
00124
00125
00126
00127 }
00128
00129
00130
00131 #endif
00132
00133
|