1 | #include "exception.hpp" |
---|
2 | |
---|
3 | /// boost headers /// |
---|
4 | #include <boost/cast.hpp> |
---|
5 | #include "client.hpp" |
---|
6 | #include "server.hpp" |
---|
7 | #include "cxios.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
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) |
---|
28 | { |
---|
29 | if (desc_rethrow) |
---|
30 | #ifdef __XIOS_NOABORT |
---|
31 | { |
---|
32 | throw (*this); |
---|
33 | } |
---|
34 | #else |
---|
35 | { |
---|
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 | |
---|
45 | StdOFStream fileStream; |
---|
46 | StdStringStream fileNameErr; |
---|
47 | std::streambuf* psbuf; |
---|
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"; |
---|
54 | |
---|
55 | |
---|
56 | fileStream.open(fileNameErr.str().c_str(), std::ofstream::out); |
---|
57 | psbuf = fileStream.rdbuf(); |
---|
58 | std::cerr.rdbuf(psbuf); |
---|
59 | std::cerr << this->getMessage() << std::endl; |
---|
60 | fileStream.close(); |
---|
61 | abort(); |
---|
62 | } |
---|
63 | |
---|
64 | #endif |
---|
65 | } |
---|
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 | |
---|
87 | } // namespace xios |
---|