Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C++

How a C++ compiler implements exception handling

Rate me:
Please Sign up or sign in to vote.
4.96/5 (196 votes)
15 Apr 2002CPOL26 min read 1.1M   6.2K   579  
An indepth discussion of how VC++ implements exception handling. Source code includes exception handling library for VC++.
#include "install_my_handler.h"
#include <iostream>

using std::cout;
using std::endl;

namespace
{
    void install_my_exc_handler()
    {
       if(my_handler::install_my_handler())
            cout<<"using my exception handler..."<<endl;
        else
            cout<<"failure in installing my handler"<<endl;
    }

    int g_i = 0;

    class E
    {
    };

    void foo()
    {
        try
        {
            cout<<"in foo()"<<endl;
            if(0 == g_i)
                throw E();
            cout<<"exiting foo()"<<endl;
        }
        catch(E&)
        {
            cout<<"caught E exception"<<endl;
        }
    }
}

int main()
{
    foo();  //use vc++ default exception handler.
    install_my_exc_handler();
    foo();
    return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions