source: XIOS/dev/dev_rv/src4/xmlio/exception.cpp @ 2338

Last change on this file since 2338 was 258, checked in by hozdoba, 13 years ago
File size: 2.6 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5/**
6 * \file    exception.cpp
7 * \brief   Gestion des erreurs levées lors de l'exécution de programme (implémentation).
8 * \author  Hervé Ozdoba
9 * \version 0.4
10 * \date    9 Juin 2011
11 */
12
13#ifndef __XIOS_NO_EXTERN
14
15// Boost headers
16#include <boost/cast.hpp>
17#include <boost/format.hpp>
18
19#endif // __XIOS_NO_EXTERN
20
21// XMLIOServer headers
22#include "xmlioserver_spl.hpp"
23
24// /////////////////////////////// Définitions ////////////////////////////// //
25
26namespace xmlioserver {
27
28   // ------------------------------ Constructeurs -----------------------------
29
30   // Constructeur simple d'une exception anonyme.
31   CException::CException(void)
32      : CObject(), desc_rethrow(true)
33   { /* Ne rien faire de plus */ }
34
35   // Constructeur simple d'une exception identifiée.
36   CException::CException(const std::string & _id)
37      : CObject(_id), desc_rethrow(true)
38   { /* Ne rien faire de plus */ }
39
40   // Constructeur par copie.
41   CException::CException(const CException & _exception)
42      : std::basic_ios<char>()
43      , CObject(_exception.getId())
44      , std::ostringstream()
45      , desc_rethrow(false)
46   {
47      (*this) << _exception.str();
48   }
49
50   // ------------------------------- Destructeur -----------------------------
51
52   // Destructeur de l'instance.
53   CException::~CException(void)
54   {
55      if (this->desc_rethrow) throw (*this);
56   }
57
58   // ------------------------------- Accesseurs ------------------------------
59
60   // Retourne un message d'erreur.
61   const std::string CException::getMessage(void) const
62   {
63      std::ostringstream oss;
64      // oss << "> Error [" << this->getId() << "] : " << this->str();
65      oss << boost::format("> Error [ %1% ] : %2%") % this->getId() % this->str(); 
66      return (oss.str());
67   }
68
69   // Retourne un flux d'écriture du message d'erreur.
70   std::ostringstream &  CException::getStream(void)
71   {
72      return (*boost::polymorphic_cast<std::ostringstream*>(this));
73   }
74
75   // --------------------------- Diverses méthodes ---------------------------
76
77   // Retourne une représentation ascii de l'objet.
78   std::string CException::toString(void) const
79   {
80      return (std::string(this->getMessage()));
81   }
82
83   // Modifie l'objet en fonction d'une chaîne de caractÚre.
84   void CException::fromString(const std::string & str)
85   {
86      this->str(str);
87   }
88
89} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.