Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- // NOTE: the value of the C/C++, Code Generation, Enable C++ Exceptions setting in important
- // Try it both with /EHsc (the default) and /EHa to see the difference
- class Example {
- public:
- ~Example() { std::cout << "destructed" << std::endl; }
- };
- int filterException(int code, PEXCEPTION_POINTERS ex) {
- std::cout << "Filtering " << std::hex << code << std::endl;
- return EXCEPTION_EXECUTE_HANDLER;
- }
- void testProcessorFault() {
- Example e;
- int* p = new int;
- delete p;
- *p = 42;
- }
- void testCppException() {
- Example e;
- throw 42;
- }
- int main()
- {
- __try {
- testProcessorFault();
- }
- __except (filterException(GetExceptionCode(), GetExceptionInformation())) {
- std::cout << "caught" << std::endl;
- }
- __try {
- testCppException();
- }
- __except (filterException(GetExceptionCode(), GetExceptionInformation())) {
- std::cout << "caught" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement