source: XIOS1/branches/xios-1.0/src/exception.cpp @ 2520

Last change on this file since 2520 was 548, checked in by rlacroix, 10 years ago

Backport r523 into the stable branch.

Improve the message error handling by mimicking the behavior of the info/report logs.

Output the error messages to the standart error message until the context is correctly initialized. Then, output the error messages to a file if the user has set "print_file" parameter to "true".

  • Fix: Errors that occured before MPI was initialized (e.g. during the config file parsing) caused a MPI error on top of the original error.
  • Fix: The error file could sometimes be misnamed if the error happened before the context was completely known.
  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 1.5 KB
Line 
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#include "log.hpp"
9
10namespace xios
11{
12  /// ////////////////////// Définitions ////////////////////// ///
13   CException::CException(void)
14      : CObject(), desc_rethrow(true)
15   { /* Ne rien faire de plus */ }
16
17   CException::CException(const StdString & id)
18      : CObject(id), desc_rethrow(true)
19   { /* Ne rien faire de plus */ }
20
21   CException::CException(const CException & exception)
22      : std::basic_ios<char>()
23      , CObject(exception.getId())
24      , StdOStringStream()
25      , desc_rethrow(false)
26   { (*this) << exception.str(); }
27
28   CException::~CException(void)
29   {
30      if (desc_rethrow)
31#ifdef __XIOS_NOABORT
32      {
33        throw (*this);
34      }
35#else
36     {
37      error << this->getMessage() << std::endl;
38      abort();
39      }
40#endif
41   }
42
43   //---------------------------------------------------------------
44
45   StdString CException::getMessage(void) const
46   {
47      StdOStringStream oss;
48      oss << "> Error [" << this->getId() << "] : " << this->str();
49      return (oss.str());
50   }
51
52   StdOStringStream &  CException::getStream(void)
53   { return (*boost::polymorphic_cast<StdOStringStream*>(this)); }
54
55   StdString CException::toString(void) const
56   { return (StdString(this->getMessage())); }
57
58   void CException::fromString(const StdString & str)
59   { this->str(str); }
60
61   //---------------------------------------------------------------
62
63} // namespace xios
Note: See TracBrowser for help on using the repository browser.