xoreos  0.0.5
error.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_ERROR_H
26 #define COMMON_ERROR_H
27 
28 #include <stack>
29 #include <exception>
30 
31 #include "src/common/ustring.h"
32 
33 namespace Common {
34 
36 class StackException : public std::exception {
37 public:
38  typedef std::stack<UString> Stack;
39 
41  StackException(const char *s, ...) GCC_PRINTF(2, 3);
43  StackException(const std::exception &e);
44  ~StackException() throw();
45 
46  void add(const char *s, ...) GCC_PRINTF(2, 3);
47  void add(const std::exception &e);
48 
49  const char *what() const throw();
50 
51  bool empty() const;
52 
53  Stack &getStack();
54 
55 private:
57 };
58 
60 
61 extern const Exception kOpenError;
62 extern const Exception kReadError;
63 extern const Exception kSeekError;
64 extern const Exception kWriteError;
65 
67 void printException(Exception &e, const UString &prefix = "ERROR: ");
68 
71 void exceptionDispatcherError(const char *s, ...) GCC_PRINTF(1, 2);
75 
78 void exceptionDispatcherWarning(const char *s, ...) GCC_PRINTF(1, 2);
82 
83 } // End of namespace Common
84 
85 #endif // COMMON_ERROR_H
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
STL namespace.
Stack & getStack()
Definition: error.cpp:84
Exception that provides a stack of explanations.
Definition: error.h:36
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
std::stack< UString > Stack
Definition: error.h:38
const Exception kWriteError("Write error")
Exception when writing to a stream failed.
Definition: error.h:64
const Exception kReadError("Read error")
Exception when reading from a stream failed.
Definition: error.h:62
Unicode string handling.
void exceptionDispatcherError(const char *s,...)
Exception dispatcher that prints the exception as an error, and adds another reason on top...
Definition: error.cpp:143
const Exception kSeekError("Seek error")
Exception when seeking a stream failed.
Definition: error.h:63
const Exception kOpenError("Can't open file")
Exception when a file couldn&#39;t be opened.
Definition: error.h:61
#define GCC_PRINTF(x, y)
Definition: system.h:161
const char * what() const
Definition: error.cpp:73
void printException(Exception &e, const UString &prefix)
Print a whole exception stack to stderr and the log.
Definition: error.cpp:95
bool empty() const
Definition: error.cpp:80