Project

General

Profile

SO3Engine
SO3Exception.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
26#include "OgreLogManager.h"
27
28namespace SO3
29{
30
31SException::SException(const std::string& desc, const std::string& src, bool exceptToLogFile) : line(0),
32 description(desc),
33 source(src),
34 toLogFile(exceptToLogFile)
35{
36 if(toLogFile)
37 {
38 try
39 {
40 Ogre::LogManager::getSingleton().logMessage(GetFullDescription(), Ogre::LML_NORMAL);
41 }
42 catch (Ogre::Exception &)
43 {
44 // could not write on log file
45 }
46 }
47}
48
49SException::SException(const std::string& desc, const std::string& src, const char* typ, const char* fil, long lin, bool exceptToLogFile) : line(lin),
50 typeName(typ),
51 description(desc),
52 source(src),
53 file(fil),
54 toLogFile(exceptToLogFile)
55{
56 if(toLogFile)
57 {
58 try
59 {
60 Ogre::LogManager::getSingleton().logMessage(GetFullDescription(), Ogre::LML_NORMAL);
61 }
62 catch (Ogre::Exception &)
63 {
64 // could not write on log file
65 }
66 }
67}
68
69SException::SException(const SException& exception) : line(exception.line),
70 typeName(exception.typeName),
71 description(exception.description),
72 source(exception.source),
73 file(exception.file),
74 toLogFile(exception.toLogFile)
75{
76}
77
79{
80}
81
82void SException::operator =(const SException& exception)
83{
84 description = exception.description;
85 source = exception.source;
86 file = exception.file;
87 line = exception.line;
88 typeName = exception.typeName;
89 toLogFile = exception.toLogFile;
90}
91
92const std::string& SException::GetFullDescription() const
93{
94 if (fullDesc.empty())
95 {
96 std::ostringstream desc;
97 desc << "SO3 EXCEPTION(" << typeName << "): " << description << " in " << source;
98
99 if(line > 0)
100 {
101 desc << " at " << file << " (line " << line << ")";
102 }
103
104 fullDesc = desc.str();
105 }
106 return fullDesc;
107}
108
109const std::string& SException::GetSource() const
110{
111 return source;
112}
113
114const std::string& SException::GetFile() const
115{
116 return file;
117}
118
120{
121 return line;
122}
123
124const std::string& SException::GetDescription() const
125{
126 return description;
127}
128
129const char* SException::what() const throw()
130{
131 return GetFullDescription().c_str();
132}
133
134SExceptionUnimplemented::SExceptionUnimplemented(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionUnimplemented", exceptFile, exceptLine, exceptToLogFile)
135{
136}
137
138SExceptionFileNotFound::SExceptionFileNotFound(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionFileNotFound", exceptFile, exceptLine, exceptToLogFile)
139{
140}
141
142SExceptionIO::SExceptionIO(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionIO", exceptFile, exceptLine, exceptToLogFile)
143{
144}
145
146SExceptionItemIdentity::SExceptionItemIdentity(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionItemIdentity", exceptFile, exceptLine, exceptToLogFile)
147{
148}
149
150SExceptionItemNotFound::SExceptionItemNotFound(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionItemNotFound", exceptFile, exceptLine, exceptToLogFile)
151{
152}
153
154SExceptionInternalError::SExceptionInternalError(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionInternalError", exceptFile, exceptLine, exceptToLogFile)
155{
156}
157
158SExceptionExternalAPIError::SExceptionExternalAPIError(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionExternalAPIError", exceptFile, exceptLine, exceptToLogFile)
159{
160}
161
162SExceptionInvalidParameters::SExceptionInvalidParameters(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionInvalidParameters", exceptFile, exceptLine, exceptToLogFile)
163{
164}
165
166SExceptionNullReference::SExceptionNullReference(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionNullReference", exceptFile, exceptLine, exceptToLogFile)
167{
168}
169
170SExceptionBadCast::SExceptionBadCast(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionBadCast", exceptFile, exceptLine, exceptToLogFile)
171{
172}
173
174SExceptionWriteData::SExceptionWriteData(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionWriteData", exceptFile, exceptLine, exceptToLogFile)
175{
176}
177
178SExceptionWriteOnly::SExceptionWriteOnly(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionWriteOnly", exceptFile, exceptLine, exceptToLogFile)
179{
180}
181
182SExceptionReadData::SExceptionReadData(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionReadData", exceptFile, exceptLine, exceptToLogFile)
183{
184}
185
186SExceptionReadOnly::SExceptionReadOnly(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionReadOnly", exceptFile, exceptLine, exceptToLogFile)
187{
188}
189
190SExceptionOutOfBound::SExceptionOutOfBound(const std::string& exceptDescription, const std::string& exceptSource, const char* exceptFile, long exceptLine, bool exceptToLogFile) : SException(exceptDescription, exceptSource, "SExceptionOutOfBound", exceptFile, exceptLine, exceptToLogFile)
191{
192}
193
194}
SExceptionBadCast(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionExternalAPIError(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionFileNotFound(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
Base class for SO3 custom exception.
virtual const std::string & GetDescription() const
virtual ~SException()
const char * what() const
std::string typeName
virtual const std::string & GetSource() const
SException(const std::string &exceptDescription, const std::string &exceptSource, bool exceptToLogFile)
virtual const std::string & GetFile() const
virtual const std::string & GetFullDescription() const
virtual long GetLine() const
std::string file
std::string fullDesc
std::string source
void operator=(const SException &exception)
std::string description
SExceptionIO(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionInternalError(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionInvalidParameters(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionItemIdentity(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionItemNotFound(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionNullReference(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionOutOfBound(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionReadData(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionReadOnly(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionUnimplemented(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionWriteData(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)
SExceptionWriteOnly(const std::string &exceptDescription, const std::string &exceptSource, const char *exceptFile, long exceptLine, bool exceptToLogFile=false)