@@ -25,7 +25,7 @@ manager: "ghogen"
2525
2626```
2727
28- __try
28+ __try
2929{
3030 // guarded code
3131}
@@ -100,73 +100,53 @@ struct _EXCEPTION_POINTERS {
100100 ** AbnormalTermination** is equivalent to _ abnormal_termination
101101
102102## Example
103- ` // exceptions_try_except_Statement.cpp `
104-
105- ` // Example of try-except and try-finally statements `
106-
107- ` #include <stdio.h> `
108-
109- ` #include <windows.h> // for EXCEPTION_ACCESS_VIOLATION `
110-
111- ` #include <excpt.h> `
112-
113- ` int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) { `
114-
115- ` puts("in filter."); `
116-
117- ` if (code == EXCEPTION_ACCESS_VIOLATION) { `
118-
119- ` puts("caught AV as expected."); `
120-
121- ` return EXCEPTION_EXECUTE_HANDLER; `
122-
123- ` } `
124-
125- ` else { `
126-
127- ` puts("didn't catch AV, unexpected."); `
128-
129- ` return EXCEPTION_CONTINUE_SEARCH; `
130-
131- ` }; `
132-
133- ` } `
134-
135- ` int main() `
136-
137- ` { `
138-
139- ` int* p = 0x00000000; // pointer to NULL `
140-
141- ` puts("hello"); `
142-
143- ` __try{ `
144-
145- ` puts("in try"); `
146-
147- ` __try{ `
148-
149- ` puts("in try"); `
150-
151- ` *p = 13; // causes an access violation exception; `
152-
153- ` }__finally{ `
154-
155- ` puts("in finally. termination: "); `
156-
157- ` puts(AbnormalTermination() ? "\tabnormal" : "\tnormal"); `
158-
159- ` } `
160-
161- ` }__except(filter(GetExceptionCode(), GetExceptionInformation())){ `
162-
163- ` puts("in except"); `
164-
165- ` } `
166-
167- ` puts("world"); `
168-
169- ` } `
103+ ```
104+ // exceptions_try_except_Statement.cpp
105+ // Example of try-except and try-finally statements
106+ #include <stdio.h>
107+ #include <windows.h> // for EXCEPTION_ACCESS_VIOLATION
108+ #include <excpt.h>
109+
110+ int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
111+ {
112+ puts("in filter.");
113+ if (code == EXCEPTION_ACCESS_VIOLATION)
114+ {
115+ puts("caught AV as expected.");
116+ return EXCEPTION_EXECUTE_HANDLER;
117+ }
118+ else
119+ {
120+ puts("didn't catch AV, unexpected.");
121+ return EXCEPTION_CONTINUE_SEARCH;
122+ };
123+ }
124+
125+ int main()
126+ {
127+ int* p = 0x00000000; // pointer to NULL
128+ puts("hello");
129+ __try
130+ {
131+ puts("in try");
132+ __try
133+ {
134+ puts("in try");
135+ *p = 13; // causes an access violation exception;
136+ }
137+ __finally
138+ {
139+ puts("in finally. termination: ");
140+ puts(AbnormalTermination() ? "\tabnormal" : "\tnormal");
141+ }
142+ }
143+ __except(filter(GetExceptionCode(), GetExceptionInformation()))
144+ {
145+ puts("in except");
146+ }
147+ puts("world");
148+ }
149+ ```
170150
171151## Output
172152
@@ -187,4 +167,4 @@ world
187167## See Also
188168 [ Writing an Exception Handler] ( ../cpp/writing-an-exception-handler.md )
189169 [ Structured Exception Handling (C/C++)] ( ../cpp/structured-exception-handling-c-cpp.md )
190- [ Keywords] ( ../cpp/keywords-cpp.md )
170+ [ Keywords] ( ../cpp/keywords-cpp.md )
0 commit comments