1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_core_Exception_hpp
38 #define anna_core_Exception_hpp
46 Excepcion generica usada en las aplicaciones functions.
48 class Exception : public std::exception {
51 * Normaliza las acciones que puede tomar un método a la hora de configurar
52 * el tratamiento de errores/excepciones.
54 struct Mode { enum _v { Ignore, Throw, Trace }; };
58 @param text Texto explicativo de la excepcion.
59 @param fromFile Fichero en el que se provoco la situacion de error.
60 @param fromLine Linea del fichero en la que se detecto el error.
62 Exception(const char* text, const char* fromFile, const int fromLine);
67 @param other Instancia de la una excepcion a partir de la que vamos a obtener los datos.
69 Exception(const Exception& other);
74 virtual ~Exception() throw() {;}
78 @return Devuelve el texto explicativo asociado a esta excepcion.
80 const std::string& getText() const throw() { return m_text;}
83 @return El nombre del fichero donde se genero la excepcion. Coincidira con el indicado
86 const char* getFromFile() const { return m_fromFile.c_str(); }
89 @return La linea del fichero donde se genero la excepcion. Coincidira con la indicada
92 int getFromLine() const throw() { return m_fromLine; }
95 Establecer un codigo de error asociado a esta excepcion.
97 @param errorCode Valor a establecer. El significado de este error dependera de la
98 interpretacion particular que queramos darle en nuestra aplicacion.
100 void setErrorCode(const int errorCode) throw() { m_errorCode = errorCode; }
103 @return El codigo de error asociado a esta excepcion.
105 int getErrorCode() const throw() { return m_errorCode; }
111 @param right Instancia de la excepcion de la que vamos a obtener los datos.
113 @return Referencia a esta instancia.
115 Exception& operator = (const Exception& right) throw();
119 Devuelve una cadena conteniendo toda la informacion referente a la excepcion
120 en un formato que sea facil de interpretar.
122 @return Instancia de la cadena conteniendo la informacion de la excepcion.
124 std::string asString() const throw();
127 Devuelve una cadena conteniendo toda la informacion referente a la excepcion
128 en un formato que sea facil de interpretar.
130 Sobreescribe el metodo de la clase base.
132 @return Puntero a la cadena conteniendo la informacion de la excepcion.
134 const char* what() const throw() { return asString().c_str(); } // JASC, 23/9/2003 antes dAata() ( no tenia el trailing null )
137 Saca una traza de error en el fichero de log con el texto asociado a este excepcion.
142 void trace() const throw();
145 Exception(const char* text, const char* name, const char* fromFile, const int fromLine);
148 Establece el texto asociado a esta excepcion.
150 @param text Nuevo texto asociado a esta excepcion.
152 void setText(const char* text) throw() { m_text = text; }
155 Establece el texto asociado a esta excepcion.
157 @param text Nuevo texto asociado a esta excepcion.
159 void setText(const std::string& text) throw() { m_text = text; }
164 std::string m_fromFile;