ctkPluginException.cxx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "ctkPluginException.h"
  2. namespace ctk {
  3. PluginException::PluginException(const QString& msg, const Type& type = UNSPECIFIED, const std::exception& cause = std::exception())
  4. : msg(msg), type(type), cause(cause)
  5. {
  6. }
  7. PluginException::PluginException(const QString& msg, const std::exception& cause)
  8. : msg(msg), type(UNSPECIFIED), cause(cause)
  9. {
  10. }
  11. PluginException::PluginException(const PluginException& o)
  12. : msg(o.msg), type(o.type), cause(o.cause)
  13. {
  14. }
  15. PluginException& PluginException::operator=(const PluginException& o)
  16. {
  17. msg = o.msg;
  18. type = o.type;
  19. cause = o.cause;
  20. return *this;
  21. }
  22. std::exception PluginException::getCause() const
  23. {
  24. return cause;
  25. }
  26. void PluginException::setCause(const std::exception& cause) throw(std::logic_error)
  27. {
  28. if (!cause.what()) throw std::logic_error("The cause for this PluginException instance is already set");
  29. this->cause = cause;
  30. }
  31. Type PluginException::getType() const
  32. {
  33. return type;
  34. }
  35. const char* PluginException::what() const throw()
  36. {
  37. return qPrintable(*this);
  38. }
  39. }
  40. QDebug operator<<(QDebug dbg, const PluginException& exc)
  41. {
  42. dbg << "PluginException:" << msg;
  43. const char* causeMsg = cause.what();
  44. if (causeMsg) dbg << " Caused by:" << cause.what();
  45. return dbg.maybeSpace();
  46. }