Xpace
exception_c.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file base/exception_c.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_EXCEPTION_C_H
13 #define XPACE_EXCEPTION_C_H
14 
15 #include "base/c/types_c.h"
16 
17 #ifdef __cplusplus
18 # include "base/exception.h"
19 
20  // ================================ ANY EXCEPTION ===========
21 
22  namespace Xpace
23  {
24  /// Never thrown, but a convenient holder for std and Xpace exceptions
25  class XPACE_EXPORT AnyException : public Xpace::Exception
26  {
27  public:
28  AnyException
29  ();
30  explicit AnyException
31  (const Xpace::Exception& ex);
32  explicit AnyException
33  (const std::exception& ex);
34 
35  /// @return true if empty
36  bool operator!
37  ()
38  const;
39 
40  const Xpace::String getTemplate
41  ()
42  const;
43 
44  String getMessage
45  (const String& templ = String())
46  const;
47 
48  Exception why
49  ();
50 
51  const char* what
52  ()
53  const throw();
54 
55  bool isBadAlloc
56  ()
57  const;
58 
59  private:
60  const Exception xpace_ex;
61  Exception cur_ex;
62  const std::exception std_ex;
63  };
64  }
65 
66  typedef Xpace::AnyException* Xpace_Error;
67 
68  XPACE_C_EXPORT(Xpace_Error) Xpace_Error_create
69  (const Xpace::Exception& ex);
70  XPACE_C_EXPORT(Xpace_Error) Xpace_Error_create_std
71  (const std::exception& ex = std::bad_alloc());
72 
73 #else
74  typedef void* Xpace_Error;
75 #endif
76 
77 extern Xpace_Error Xpace_Error_None;
78 
79 XPACE_C_EXPORT(Xpace_Error) Xpace_Error_copy
80  (Xpace_Error);
81 
82 XPACE_C_EXPORT(void) Xpace_Error_destroy
83  (Xpace_Error);
84 
85 /// Get to the error that cause this one (if any)
86 /// @return the error we there is such an error
87 XPACE_C_EXPORT(Xpace_Error) Xpace_Error_why
88  (Xpace_Error);
89 
90 /// @return English template into which params will be inserted
91 XPACE_C_EXPORT(const Xpace_Char16*) Xpace_Error_getTemplate
92  (Xpace_Error);
93 
94 /// Construct an error message
95 /// @param templ the template into which params will be inserted
96 /// (I.e., a translation of getTemplate() for this exception)
97 /// if = Xpace_String(), use English template
98 /// @return the translated template with params insterted
99 XPACE_C_EXPORT(const Xpace_Char16*) Xpace_Error_getMessage
100  (Xpace_Error,
102 
103 /// @return an English error message with params inserted
104 XPACE_C_EXPORT(char*) Xpace_Error_what
105  (const Xpace_Error);
106 
107 #ifdef __cplusplus
108  #define CALL_CATCH(x) \
109  try \
110  { \
111  x; \
112  } \
113  catch (Xpace::Exception& ex) \
114  { \
115  return Xpace_Error_create(ex); \
116  } \
117  catch (std::exception& ex) \
118  { \
119  return Xpace_Error_create_std(ex); \
120  } \
121  return Xpace_Error_None;
122 #endif
123 
124 #endif
A low-level data holder.
Definition: types_c.h:82
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
STL namespace.
XPACE_C_EXPORT(Xpace_Error) Xpace_Error_copy(Xpace_Error)
Get to the error that cause this one (if any)
uint16 Xpace_Char16
Definition: types_c.h:58
const Xpace_Char16 * templ
Definition: exception_c.h:101
Xpace_Error Xpace_Error_None
void * Xpace_Error
Definition: exception_c.h:74
Xpace project main namespace
Definition: datetime.h:18

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