ctkPluginException.cpp

Go to the documentation of this file.
00001 /*=============================================================================
00002 
00003   Library: CTK
00004 
00005   Copyright (c) 2010 German Cancer Research Center,
00006     Division of Medical and Biological Informatics
00007 
00008   Licensed under the Apache License, Version 2.0 (the "License");
00009   you may not use this file except in compliance with the License.
00010   You may obtain a copy of the License at
00011 
00012     http://www.apache.org/licenses/LICENSE-2.0
00013 
00014   Unless required by applicable law or agreed to in writing, software
00015   distributed under the License is distributed on an "AS IS" BASIS,
00016   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017   See the License for the specific language governing permissions and
00018   limitations under the License.
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 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines