]> git.lyx.org Git - lyx.git/blob - src/support/ExceptionMessage.h
Move python related functions together to make it easy to read the code.
[lyx.git] / src / support / ExceptionMessage.h
1 // -*- C++ -*-
2 /**
3  * \file ExceptionMessage.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  */
12 #ifndef LYX_MESSAGE_H
13 #define LYX_MESSAGE_H
14
15 #include "support/docstring.h"
16
17 #include <exception>
18
19 namespace lyx {
20 namespace support {
21
22 /// LyX support three types of custom exceptions. In order of
23 /// increasing seriousness, these are:
24 ///
25 /// WarningException
26 ///   Intended for unexpected situations that we do not expect
27 ///   to compromise further operation. It has the effect of
28 ///   aborting whatever operation in in process.
29 ///
30 /// BufferException
31 ///   Intended for situations that indicate some problem with a
32 ///   Buffer or its related data structures. The Buffer will be
33 ///   closed, in emergency style.
34 ///
35 /// ErrorException
36 ///   Intended for situations that indicate a global problem
37 ///   with the program. It will lead to an emergency shutdown.
38
39 enum ExceptionType {
40         ErrorException,
41         BufferException,
42         WarningException
43 };
44
45
46 class ExceptionMessage: public std::exception {
47 public:
48         ExceptionMessage(ExceptionType type, docstring const & title,
49                 docstring const & details)
50         : type_(type), title_(title), details_(details),
51           message_(to_utf8(title_ + docstring::value_type('\n') + details_)) {}
52
53         virtual const char * what() const throw() { return message_.c_str(); }
54         virtual ~ExceptionMessage() throw() {}
55
56         ExceptionType type_;
57         docstring title_;
58         docstring details_;
59         // Needed because we may not return a temporary in what().
60         std::string message_;
61 };
62
63 } // namespace support
64 } // namespace lyx
65
66 #endif // LYX_MESSAGE_H