Skip to content

Commit ea9651c

Browse files
Update set-se-translator.md
Improved examples according to https://github.com/MicrosoftDocs/cpp-docs/issues/735 - Make exception classes inherit std::exception - Make exception class naming consistent in both samples - Fixed second example not using exception number
1 parent 687487b commit ea9651c

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎docs/c-runtime-library/reference/set-se-translator.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ For more compatibility information, see [Compatibility](../../c-runtime-library/
6767
#include <stdio.h>
6868
#include <windows.h>
6969
#include <eh.h>
70+
#include <exception>
7071
71-
class SE_Exception
72+
class SE_Exception : public std::exception
7273
{
7374
private:
7475
unsigned int nSE;
@@ -131,6 +132,7 @@ Although the functionality provided by **_set_se_translator** is not available i
131132
#include <eh.h>
132133
#include <assert.h>
133134
#include <stdio.h>
135+
#include <exception>
134136

135137
int thrower_func(int i) {
136138
int y = 0;
@@ -139,19 +141,19 @@ int thrower_func(int i) {
139141
return 0;
140142
}
141143

142-
class CMyException{
144+
class SE_Exception : public std::exception {
143145
private:
144146
unsigned int nSE;
145147
public:
146-
CMyException() : nSE{ 0 } {}
147-
CMyException(unsigned int n) : nSE{ n } {}
148+
SE_Exception() : nSE{ 0 } {}
149+
SE_Exception(unsigned int n) : nSE{ n } {}
148150
unsigned int getSeNumber() { return nSE; }
149151
};
150152

151153
#pragma unmanaged
152154
void my_trans_func(unsigned int u, PEXCEPTION_POINTERS)
153155
{
154-
throw CMyException(u);
156+
throw SE_Exception(u);
155157
}
156158

157159
void DoTest()
@@ -160,9 +162,9 @@ void DoTest()
160162
{
161163
thrower_func(10);
162164
}
163-
catch(CMyException e)
165+
catch(SE_Exception& e)
164166
{
165-
printf("Caught CMyException.\n");
167+
printf("Caught SE_Exception, error %8.8x\n", e.getSeNumber());
166168
}
167169
catch(...)
168170
{
@@ -179,7 +181,7 @@ int main() {
179181
```
180182
181183
```Output
182-
Caught CMyException, error c0000094
184+
Caught SE_Exception, error c0000094
183185
```
184186

185187
## See also

0 commit comments

Comments
 (0)