Xpace
exception.h
Go to the documentation of this file.
1 
2 /************************************************************
3  **
4  ** @file base/exception.h
5  **
6  ** Copyright (C) 2016 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_EXCEPTION_H
13 #define XPACE_EXCEPTION_H
14 
15 #include <exception>
16 #include <vector>
17 
18 #include "base/types.h"
19 
20 #if defined(MSVC_VERSION)
21 #pragma warning(disable: 4275)
22 #endif
23 
24 namespace Xpace
25 {
26  class exceptionImpl;
27 
28  class XPACE_EXPORT Exception : public std::exception
29  {
30  public:
31  Exception
32  ();
33  Exception
34  (const Exception&);
35  Exception& operator=
36  (const Exception&);
37  virtual ~Exception
38  () throw();
39 
40  /// @return true if empty
41  bool operator!
42  ()
43  const;
44 
45  /// @return the exception that caused this one (if any)
46  const Exception why
47  ()
48  const;
49 
50  /// @return the version string for the Xpace libraries
51  const char* versionInfo
52  ()
53  const;
54 
55  /// @return English template into which params will be inserted
56  const String getTemplate
57  ()
58  const;
59 
60  /// Construct an error message
61  /// @param templ the template into which params will be inserted
62  /// (I.e., a translation of getTemplate() for this exception)
63  /// if = String(), use English template
64  /// @return the translated template with params insterted
65  String getMessage
66  (const String& templ = String())
67  const;
68 
69  /// @return an English error message with params inserted
70  const char* what()
71  const throw();
72 
73  protected:
74  /// @param templ construct an Exception with this message template
75  /// @param reason cause for this Exception, if any
76  Exception
77  (const String& templ,
78  const Exception reason = Exception());
79 
80  /// Add a parameter to this exception
81  /// The first parameter added will replace '%1' in the template,
82  /// the second will replace '%2', and so on.
83  /// @param p the param to be added
84  void addParam
85  (const String& p);
86 
87  private:
88  friend class exceptionImpl;
89  exceptionImpl* impl;
90  Exception
91  (const exceptionImpl* i);
92  };
93 
94  /// General exceptions
95 
97  {
98  public:
99  /// @param desc a description
101  (const String& desc);
102  };
103 
104  class Bounds_Error : public Exception
105  {
106  public:
107  /// @param bad the bad vslue
108  /// @param max the maximum it should be
110  (int64 bad,
111  int64 max);
112  };
113 
115  {
116  public:
117  /// @param desc what is corrupt
118  /// @param pos where it is corrupt
120  (String desc,
121  int64 pos);
122  };
123 }
124 
125 #endif
A low-level data holder.
Definition: types_c.h:82
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
General exceptions.
Definition: exception.h:96
const Xpace_Char16 * templ
Definition: exception_c.h:101
long long int64
Definition: types.h:86
Xpace project main namespace
Definition: datetime.h:18

current as of Wed Jun 10 2026 12:00:05