Remove dynamic exceptions
[anna.git] / source / core / Exception.cpp
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 #include <stdio.h>
10
11 #include <anna/core/RuntimeException.hpp>
12 #include <anna/core/tracing/Logger.hpp>
13
14 using namespace anna;
15
16 Exception::Exception(const char* text, const char* name, const char* fromFile, const int fromLine) :
17   m_errorCode(-1) {
18   m_text = text;
19   m_name = name;
20   m_fromFile = fromFile;
21   m_fromLine = fromLine;
22 }
23
24 Exception::Exception(const char* text, const char* fromFile, const int fromLine)  :
25   m_errorCode(-1) {
26   m_text = text;
27   m_name = "Exception";
28   m_fromFile = fromFile;
29   m_fromLine = fromLine;
30 }
31
32 Exception::Exception(const Exception& other) {
33   m_text = other.m_text;
34   m_name = other.m_name;
35   m_fromFile = other.m_fromFile;
36   m_fromLine = other.m_fromLine;
37   m_errorCode = other.m_errorCode;
38 }
39
40 //-----------------------------------------------------------------------
41 // Operador copia
42 //-----------------------------------------------------------------------
43 Exception& Exception::operator = (const Exception & other)
44 {
45   if(this != &other) {
46     m_name = other.m_name;
47     m_text = other.m_text;
48     m_fromFile = other.m_fromFile;
49     m_fromLine = other.m_fromLine;
50     m_errorCode = other.m_errorCode;
51   }
52
53   return *this;
54 }
55
56 std::string Exception::asString() const
57 {
58   std::string result;
59   char n [32];
60   sprintf(n, " (%d) ] ", m_fromLine);
61   result = "[ ";
62   result += m_fromFile;
63   result += n;
64   result += m_name;
65   result += ": ";
66   result += m_text;
67   return result;
68 }
69
70 void Exception::trace() const
71 {
72   Logger::write(Logger::Error, m_name.c_str(), m_text.c_str(), m_fromFile.c_str(), m_fromLine);       // JEDS 24/09/2003
73 }