STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vcruntime_exception.h
Go to the documentation of this file.
1 //
2 // vcruntime_exception.h
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // <exception> functionality that is implemented in the VCRuntime.
7 //
8 #pragma once
9 
10 #include <eh.h>
11 
12 #ifdef _M_CEE_PURE
13  #include <vcruntime_new.h>
14 #endif
15 
16 #pragma pack(push, _CRT_PACKING)
17 #if !defined RC_INVOKED && _HAS_EXCEPTIONS
18 
20 
21 struct __std_exception_data
22 {
23  char const* _What;
24  bool _DoFree;
25 };
26 
27 _VCRTIMP void __cdecl __std_exception_copy(
28  _In_ __std_exception_data const* _From,
29  _Out_ __std_exception_data* _To
30  );
31 
32 _VCRTIMP void __cdecl __std_exception_destroy(
33  _Inout_ __std_exception_data* _Data
34  );
35 
37 
38 
39 
40 namespace std {
41 
42 class exception
43 {
44 public:
45 
46  exception() throw()
47  : _Data()
48  {
49  }
50 
51  explicit exception(char const* const _Message) throw()
52  : _Data()
53  {
54  __std_exception_data _InitData = { _Message, true };
55  __std_exception_copy(&_InitData, &_Data);
56  }
57 
58  exception(char const* const _Message, int) throw()
59  : _Data()
60  {
61  _Data._What = _Message;
62  }
63 
64  exception(exception const& _Other) throw()
65  : _Data()
66  {
67  __std_exception_copy(&_Other._Data, &_Data);
68  }
69 
70  exception& operator=(exception const& _Other) throw()
71  {
72  if (this == &_Other)
73  {
74  return *this;
75  }
76 
77  __std_exception_destroy(&_Data);
78  __std_exception_copy(&_Other._Data, &_Data);
79  return *this;
80  }
81 
82  virtual ~exception() throw()
83  {
84  __std_exception_destroy(&_Data);
85  }
86 
87  virtual char const* what() const
88  {
89  return _Data._What ? _Data._What : "Unknown exception";
90  }
91 
92 private:
93 
94  __std_exception_data _Data;
95 };
96 
97 class bad_exception
98  : public exception
99 {
100 public:
101 
102  bad_exception() throw()
103  : exception("bad exception", 1)
104  {
105  }
106 };
107 
108 class bad_alloc
109  : public exception
110 {
111 public:
112 
113  bad_alloc() throw()
114  : exception("bad allocation", 1)
115  {
116  }
117 
118 private:
119 
120  friend class bad_array_new_length;
121 
122  bad_alloc(char const* const _Message) throw()
123  : exception(_Message, 1)
124  {
125  }
126 };
127 
128 class bad_array_new_length
129  : public bad_alloc
130 {
131 public:
132 
133  bad_array_new_length() throw()
134  : bad_alloc("bad array new length")
135  {
136  }
137 };
138 
139 } // namespace std
140 
141 #endif // !RC_INVOKED && _HAS_EXCEPTIONS
142 #pragma pack(pop)
143 
144 /*
145  * Copyright (c) 1992-2012 by P.J. Plauger. ALL RIGHTS RESERVED.
146  * Consult your license regarding permissions and restrictions.
147  V6.00:0009 */
#define _Out_
Definition: sal.h:342
#define _VCRTIMP
Definition: vcruntime.h:115
Definition: array:21
STL namespace.
Definition: exception:160
#define _CRT_BEGIN_C_HEADER
Definition: vcruntime.h:73
#define _In_
Definition: sal.h:305
#define _CRT_END_C_HEADER
Definition: vcruntime.h:76
Definition: exception:139
Definition: exception:80
#define _Inout_
Definition: sal.h:375