]> Creatis software - crea.git/blob - src/creaException.h
Feature #1763
[crea.git] / src / creaException.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */ 
24
25 /*=========================================================================
26                                                                                 
27   Program:   crea
28   Module:    $RCSfile: creaException.h,v $
29   Language:  C++
30   Date:      $Date: 2012/11/15 09:07:32 $
31   Version:   $Revision: 1.3 $
32                                                                                 
33                                                                                  
34      This software is distributed WITHOUT ANY WARRANTY; without even
35      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
36      PURPOSE.  See the above copyright notices for more information.
37                                                                                 
38 =========================================================================*/
39
40
41 /**
42  *  \file 
43  *  \brief  class Exception:generic class for throwing any exception (header) 
44  *
45  *    Long description:
46  */
47
48 /**
49  *  \class crea::Exception 
50  *  \brief  class Exception : generic class for throwing any exception 
51  *
52  *    Long description:
53  */
54  
55 #ifndef __creaException_h__
56 #define __creaException_h__
57
58 #include "creaSystem.h"
59 #include "creaMessageManager.h"
60 #include <exception>
61
62 namespace crea
63 {
64   inline std::string bbGetObjectDescription() { return(""); }
65
66   class CREA_EXPORT Exception : public std::exception
67   {
68   public:
69     Exception(const std::string& object,
70               const std::string& source_file,
71               const std::string& message) throw()
72       : mObject(object),
73         mSourceFile(source_file),
74         mMessage(message)
75     {
76        mWhatMessage = " * ERROR  : " + mMessage 
77                     + " * OBJECT : " + mObject
78                     + " * FILE "     + mSourceFile;
79     }
80     ~Exception() throw() {}
81    virtual const char* what() const throw() 
82    {
83       return mWhatMessage.c_str();
84    }
85
86     void Print() throw()
87     {
88       std::cerr << "* ERROR  : " << mMessage <<std::endl; 
89       int lev = crea::MessageManager::GetMessageLevel("Error");
90       if (lev > 0) {
91         std::cerr << "* OBJECT : " <<mObject<<std::endl;
92         std::cerr << "* FILE   : " <<mSourceFile<<std::endl;
93       }
94     }
95     const std::string& GetObject()     const { return mObject;     }
96     const std::string& GetSourceFile() const { return mSourceFile; }
97     const std::string& GetMessage()    const { return mMessage;    }
98   private:
99     std::string mObject;
100     std::string mSourceFile;
101     std::string mMessage;
102     std::string mWhatMessage;
103   };
104
105 }//namespace
106
107 #endif