ctkPluginException.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ctkPluginException.h"
00023
00024
00025 ctkPluginException::ctkPluginException(const QString& msg, const Type& type, const std::exception& cause)
00026 : std::runtime_error(msg.toStdString()),
00027 type(type), cause(cause)
00028 {
00029
00030 }
00031
00032 ctkPluginException::ctkPluginException(const QString& msg, const std::exception& cause)
00033 : std::runtime_error(msg.toStdString()),
00034 type(UNSPECIFIED), cause(cause)
00035 {
00036
00037 }
00038
00039 ctkPluginException::ctkPluginException(const ctkPluginException& o)
00040 : std::runtime_error(o.what()), type(o.type), cause(o.cause)
00041 {
00042
00043 }
00044
00045 ctkPluginException& ctkPluginException::operator=(const ctkPluginException& o)
00046 {
00047 std::runtime_error::operator=(o);
00048 type = o.type;
00049 cause = o.cause;
00050 return *this;
00051 }
00052
00053 std::exception ctkPluginException::getCause() const
00054 {
00055 return cause;
00056 }
00057
00058 void ctkPluginException::setCause(const std::exception& cause) throw(std::logic_error)
00059 {
00060 if (!cause.what()) throw std::logic_error("The cause for this ctkPluginException instance is already set");
00061
00062 this->cause = cause;
00063 }
00064
00065 ctkPluginException::Type ctkPluginException::getType() const
00066 {
00067 return type;
00068 }
00069
00070 const char* ctkPluginException::what() const throw()
00071 {
00072 static std::string fullMsg;
00073 fullMsg = std::string(std::runtime_error::what());
00074 const char* causeMsg = getCause().what();
00075 if (causeMsg) fullMsg += std::string("\n Caused by: ") + causeMsg;
00076
00077 return fullMsg.c_str();
00078 }
00079
00080
00081 QDebug operator<<(QDebug dbg, const ctkPluginException& exc)
00082 {
00083 dbg << "ctkPluginException:" << exc.what();
00084
00085 const char* causeMsg = exc.getCause().what();
00086 if (causeMsg) dbg << " Caused by:" << causeMsg;
00087
00088 return dbg.maybeSpace();
00089 }