Remove dynamic exceptions
[anna.git] / include / anna / core / RuntimeException.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_core_RuntimeException_hpp
10 #define anna_core_RuntimeException_hpp
11
12 #include <errno.h>
13 #include <string.h>
14
15 #include <anna/core/Exception.hpp>
16
17 namespace anna {
18
19 /**
20    Excepcion lanzada durante la ejecucion de un caso de prueba al comprobar
21    que alguna situacion es anomala.
22 */
23 class RuntimeException : public Exception {
24 public:
25   /**
26     Constructor.
27   *
28     @param text Texto con la explicacion de la excepcion.
29     @param fromFile Fichero en el que se provoco la situacion de error.
30     @param fromLine Linea del fichero en la que se provoco la situacion de error.
31   */
32   RuntimeException(const char* text, const char* fromFile, const int fromLine) :
33     Exception(text, "RuntimeException", fromFile, fromLine),
34     a_errno(-1) {}
35
36   /**
37     Constructor.
38   *
39     @param text Texto con la explicacion de la excepcion.
40     @param fromFile Fichero en el que se provoco la situacion de error.
41     @param fromLine Linea del fichero en la que se provoco la situacion de error.
42   */
43   explicit RuntimeException(const std::string& text, const char* fromFile, const int fromLine) :
44     Exception(text.c_str(), "RuntimeException", fromFile, fromLine),
45     a_errno(-1) {}
46
47   /**
48     Constructor.
49   *
50     @param fileName Nombre del fichero sobre el que actuabamos
51     \param xerrno Numero de error (errno) generado por la ultima operacion de IO o SO.
52     @param fromFile Fichero en el que se provoco la situacion de error.
53     @param fromLine Linea del fichero en la que se provoco la situacion de error.
54   */
55   explicit RuntimeException(const std::string& fileName, const int xerrno, const char* fromFile, const int fromLine) :
56     Exception(std::string(fileName + ": "  + strerror(xerrno)).c_str(), "RuntimeException", fromFile, fromLine),
57     a_errno(xerrno) {}
58
59   /**
60     Constructor Copia.
61     @param other Instancia de la que obtener la informacion.
62   */
63   RuntimeException(const RuntimeException& other) : Exception(other),
64     a_errno(other.a_errno)
65   {;}
66
67   /**
68     Constructor Copia.
69     @param other Instancia de la que obtener la informacion.
70   */
71   RuntimeException(const Exception& other) : Exception(other),
72     a_errno(-1)
73   {;}
74
75   /**
76     @return El numero de error con el que se inicio la excepcion.
77   */
78   int getErrorNumber() const { return a_errno; }
79
80 private:
81   const int a_errno;
82 };
83
84 } //namespace anna
85
86 #endif
87