exception.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "exception.hpp"
  2. /// boost headers ///
  3. #include <boost/cast.hpp>
  4. #include "client.hpp"
  5. #include "server.hpp"
  6. #include "cxios.hpp"
  7. #include "log.hpp"
  8. namespace xios
  9. {
  10. /// ////////////////////// Définitions ////////////////////// ///
  11. CException::CException(void)
  12. : CObject(), desc_rethrow(true)
  13. { /* Ne rien faire de plus */ }
  14. CException::CException(const StdString & id)
  15. : CObject(id), desc_rethrow(true)
  16. { /* Ne rien faire de plus */ }
  17. CException::CException(const CException & exception)
  18. : std::basic_ios<char>()
  19. , CObject(exception.getId())
  20. , StdOStringStream()
  21. , desc_rethrow(false)
  22. { (*this) << exception.str(); }
  23. CException::~CException(void)
  24. {
  25. if (desc_rethrow)
  26. #ifdef __XIOS_NOABORT
  27. {
  28. throw (*this);
  29. }
  30. #else
  31. {
  32. error << this->getMessage() << std::endl;
  33. MPI_Abort(CXios::globalComm, -1); //abort();
  34. }
  35. #endif
  36. }
  37. //---------------------------------------------------------------
  38. StdString CException::getMessage(void) const
  39. {
  40. StdOStringStream oss;
  41. oss << "> Error [" << this->getId() << "] : " << this->str();
  42. return (oss.str());
  43. }
  44. StdOStringStream & CException::getStream(void)
  45. { return (*boost::polymorphic_cast<StdOStringStream*>(this)); }
  46. StdString CException::toString(void) const
  47. { return (StdString(this->getMessage())); }
  48. void CException::fromString(const StdString & str)
  49. { this->str(str); }
  50. //---------------------------------------------------------------
  51. } // namespace xios