Click here to Skip to main content
Click here to Skip to main content
 

How a C++ compiler implements exception handling

By , 15 Apr 2002
 
exceptionhandler_src.zip
demo.dsp
demo.dsw
excpt_helper.exp
excpt_helper.lib
excptstorage.dsp
excptstorage.dsw
MyExcHandler.dsp
MyExcHandler.dsw
#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 use 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)

About the Author

Vishal Kochhar
Web Developer
Canada Canada
Member
No Biography provided

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 16 Apr 2002
Article Copyright 2002 by Vishal Kochhar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid