source: XMLIO_V2/dev/dev_rv/src4/xmlio/exception.cpp @ 229

Last change on this file since 229 was 229, checked in by hozdoba, 13 years ago
File size: 2.4 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
18#endif // __XIOS_NO_EXTERN
19
20// XMLIOServer headers
21#include "xmlioserver_spl.hpp"
22
23// /////////////////////////////// Définitions ////////////////////////////// //
24
25namespace xmlioserver {
26
27   // ------------------------------ Constructeurs -----------------------------
28
29   // Constructeur simple d'une exception anonyme.
30   CException::CException(void)
31      : CObject(), desc_rethrow(true)
32   { /* Ne rien faire de plus */ }
33
34   // Constructeur simple d'une exception identifiée.
35   CException::CException(const std::string & _id)
36      : CObject(_id), desc_rethrow(true)
37   { /* Ne rien faire de plus */ }
38
39   // Constructeur par copie.
40   CException::CException(const CException & _exception)
41      : std::basic_ios<char>()
42      , CObject(_exception.getId())
43      , std::ostringstream()
44      , desc_rethrow(false)
45   {
46      (*this) << _exception.str();
47   }
48
49   // ------------------------------- Destructeur -----------------------------
50
51   // Destructeur de l'instance.
52   CException::~CException(void)
53   {
54      if (desc_rethrow) throw (*this);
55   }
56
57   // ------------------------------- Accesseurs ------------------------------
58
59   // Retourne un message d'erreur.
60   const std::string CException::getMessage(void) const
61   {
62      std::ostringstream oss;
63      oss << "> Error [" << this->getId() << "] : " << this->str();
64      return (oss.str());
65   }
66
67   // Retourne un flux d'écriture du message d'erreur.
68   std::ostringstream &  CException::getStream(void)
69   {
70      return (*boost::polymorphic_cast<std::ostringstream*>(this));
71   }
72
73   // --------------------------- Diverses méthodes ---------------------------
74
75   // Retourne une représentation ascii de l'objet.
76   std::string CException::toString(void) const
77   {
78      return (std::string(this->getMessage()));
79   }
80
81   // Modifie l'objet en fonction d'une chaîne de caractÚre.
82   void CException::fromString(const std::string & str)
83   {
84      this->str(str);
85   }
86
87} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.