]> git.lyx.org Git - lyx.git/blob - src/support/ExceptionMessage.h
Use explicit macro to declare that we want to use C++11
[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  * A store of the paths to the various different directoies used
12  * by LyX. These paths differ markedly from one OS to another,
13  * following the local Windows, MacOS X or Posix conventions.
14  */
15 #ifndef LYX_MESSAGE_H
16 #define LYX_MESSAGE_H
17
18 #include "support/docstring.h"
19
20 #include <exception>
21
22 namespace lyx {
23 namespace support {
24
25 /// LyX support three types of custom exceptions. In order of
26 /// increasing seriousness, these are:
27 ///
28 /// WarningException
29 ///   Intended for unexpected situations that we do not expect
30 ///   to compromise further operation. It has the effect of 
31 ///   aborting whatever operation in in process.
32 ///
33 /// BufferException
34 ///   Intended for situations that indicate some problem with a
35 ///   Buffer or its related data structures. The Buffer will be
36 ///   closed, in emergency style.
37 ///
38 /// ErrorException
39 ///   Intended for situations that indicate a global problem 
40 ///   with the program. It will lead to an emergency shutdown.
41
42 enum ExceptionType {
43         ErrorException,
44         BufferException,
45         WarningException
46 };
47
48
49 class ExceptionMessage: public std::exception {
50 public:
51         ExceptionMessage(ExceptionType type, docstring const & title,
52                 docstring const & details)
53         : type_(type), title_(title), details_(details),
54           message_(to_utf8(title_ + docstring::value_type('\n') + details_)) {}
55
56         virtual const char * what() const throw() { return message_.c_str(); }
57         virtual ~ExceptionMessage() throw() {}
58
59         ExceptionType type_;
60         docstring title_;
61         docstring details_;
62         // Needed because we may not return a temporary in what().
63         std::string message_;
64 };
65
66 } // namespace support
67 } // namespace lyx
68
69 #endif // LYX_MESSAGE_H