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 | StdOFStream fileStream; |
---|
37 | StdStringStream fileNameErr; |
---|
38 | std::streambuf* psbuf; |
---|
39 | if (CXios::isClient) fileNameErr<< CXios::errorFile <<"_client_" << CClient::getRank() << ".err"; |
---|
40 | else fileNameErr<< CXios::errorFile <<"_server_" << CServer::getRank() << ".err"; |
---|
41 | |
---|
42 | fileStream.open(fileNameErr.str().c_str(), std::ofstream::out); |
---|
43 | psbuf = fileStream.rdbuf(); |
---|
44 | std::cerr.rdbuf(psbuf); |
---|
45 | std::cerr << this->getMessage() << std::endl; |
---|
46 | fileStream.close(); |
---|
47 | abort(); |
---|
48 | } |
---|
49 | |
---|
50 | #endif |
---|
51 | } |
---|
52 | |
---|
53 | //--------------------------------------------------------------- |
---|
54 | |
---|
55 | StdString CException::getMessage(void) const |
---|
56 | { |
---|
57 | StdOStringStream oss; |
---|
58 | oss << "> Error [" << this->getId() << "] : " << this->str(); |
---|
59 | return (oss.str()); |
---|
60 | } |
---|
61 | |
---|
62 | StdOStringStream & CException::getStream(void) |
---|
63 | { return (*boost::polymorphic_cast<StdOStringStream*>(this)); } |
---|
64 | |
---|
65 | StdString CException::toString(void) const |
---|
66 | { return (StdString(this->getMessage())); } |
---|
67 | |
---|
68 | void CException::fromString(const StdString & str) |
---|
69 | { this->str(str); } |
---|
70 | |
---|
71 | //--------------------------------------------------------------- |
---|
72 | |
---|
73 | } // namespace xios |
---|