andruhovski icon

SP-0301b

andruhovski | PRO | 02/15/15 08:35:10 PM UTC | 0 ⭐ | 10636 👁️ | Never ⏰ | []
C++ (WinAPI) |

0 B

|

None

|

0 👍

/

0 👎

// exception_set_terminate.cpp
// compile with: /EHsc
//http://www.argc-argv.com/5_****/article01.pdf
#include "stdafx.h"
#include <exception>
#include <iostream>
 
using namespace std;
 
void termfunction()
{
    cout << "My terminate function called." << endl;
    abort();
    exit(EXIT_FAILURE);
}
 
void uefunction()
{
    cout << "My unhandled exception function called." << endl;
    terminate(); // this is what unexpected() calls by default
}
 
void func(){
    int x = 1;
    throw bad_alloc();
    cout << x / (++x - 2) << endl;
    //terminate();
}
 
int main()
{
    terminate_handler  oldHandler1 = set_terminate(termfunction);
    unexpected_handler oldHandler2 = set_unexpected(uefunction);
 
    // Throwing an unhandled exception would also terminate the program
    // or we could explicitly call terminate();
    func();
    return 1;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎