[219] | 1 | #include "exception.hpp" |
---|
| 2 | |
---|
| 3 | /// boost headers /// |
---|
| 4 | #include <boost/cast.hpp> |
---|
[497] | 5 | #include "client.hpp" |
---|
| 6 | #include "server.hpp" |
---|
| 7 | #include "cxios.hpp" |
---|
[219] | 8 | |
---|
[335] | 9 | namespace xios |
---|
[219] | 10 | { |
---|
| 11 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 12 | CException::CException(void) |
---|
| 13 | : CObject(), desc_rethrow(true) |
---|
| 14 | { /* Ne rien faire de plus */ } |
---|
| 15 | |
---|
| 16 | CException::CException(const StdString & id) |
---|
| 17 | : CObject(id), desc_rethrow(true) |
---|
| 18 | { /* Ne rien faire de plus */ } |
---|
| 19 | |
---|
| 20 | CException::CException(const CException & exception) |
---|
| 21 | : std::basic_ios<char>() |
---|
| 22 | , CObject(exception.getId()) |
---|
| 23 | , StdOStringStream() |
---|
| 24 | , desc_rethrow(false) |
---|
| 25 | { (*this) << exception.str(); } |
---|
| 26 | |
---|
| 27 | CException::~CException(void) |
---|
[497] | 28 | { |
---|
[278] | 29 | if (desc_rethrow) |
---|
| 30 | #ifdef __XIOS_NOABORT |
---|
[497] | 31 | { |
---|
| 32 | throw (*this); |
---|
| 33 | } |
---|
[278] | 34 | #else |
---|
[497] | 35 | { |
---|
[499] | 36 | int numDigit = 0; |
---|
| 37 | int size = 0; |
---|
| 38 | MPI_Comm_size(CXios::globalComm, &size); |
---|
| 39 | while (size) |
---|
| 40 | { |
---|
| 41 | size /= 10; |
---|
| 42 | ++numDigit; |
---|
| 43 | } |
---|
| 44 | |
---|
[497] | 45 | StdOFStream fileStream; |
---|
| 46 | StdStringStream fileNameErr; |
---|
| 47 | std::streambuf* psbuf; |
---|
[499] | 48 | if (CXios::isServerSide) |
---|
| 49 | fileNameErr << CXios::serverFile << "_" << std::setfill('0') |
---|
| 50 | << std::setw(numDigit) << CServer::getRank() << ".err"; |
---|
| 51 | else |
---|
| 52 | fileNameErr << CXios::clientFile << "_" << std::setfill('0') |
---|
| 53 | << std::setw(numDigit) << CClient::getRank() << ".err"; |
---|
[497] | 54 | |
---|
[499] | 55 | |
---|
[497] | 56 | fileStream.open(fileNameErr.str().c_str(), std::ofstream::out); |
---|
| 57 | psbuf = fileStream.rdbuf(); |
---|
| 58 | std::cerr.rdbuf(psbuf); |
---|
[278] | 59 | std::cerr << this->getMessage() << std::endl; |
---|
[497] | 60 | fileStream.close(); |
---|
[278] | 61 | abort(); |
---|
[497] | 62 | } |
---|
| 63 | |
---|
[278] | 64 | #endif |
---|
| 65 | } |
---|
[219] | 66 | |
---|
| 67 | //--------------------------------------------------------------- |
---|
| 68 | |
---|
| 69 | StdString CException::getMessage(void) const |
---|
| 70 | { |
---|
| 71 | StdOStringStream oss; |
---|
| 72 | oss << "> Error [" << this->getId() << "] : " << this->str(); |
---|
| 73 | return (oss.str()); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | StdOStringStream & CException::getStream(void) |
---|
| 77 | { return (*boost::polymorphic_cast<StdOStringStream*>(this)); } |
---|
| 78 | |
---|
| 79 | StdString CException::toString(void) const |
---|
| 80 | { return (StdString(this->getMessage())); } |
---|
| 81 | |
---|
| 82 | void CException::fromString(const StdString & str) |
---|
| 83 | { this->str(str); } |
---|
| 84 | |
---|
| 85 | //--------------------------------------------------------------- |
---|
| 86 | |
---|
[335] | 87 | } // namespace xios |
---|