Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ question - Further Info in a Catch(...)?

  • 22-02-2005 4:48pm
    #1
    Registered Users, Registered Users 2 Posts: 3,888 ✭✭✭


    Hi,
    CPP question (ms compiler)
    is there any information that can be gained in the catch(...) block.
    like the line number or nestled function - other than the fact that it
    just failed somewhere between in the try block.

    try
    {
    .... lots of lines
    int x = 1/0; //math errors
    char p = *(0); // null pointer exception, mfc api network errors etc
    .... lots of lines
    }
    catch(...)
    {
    //Line number = ??
    }

    thanks,
    ozmo.

    “Roll it back”



Comments

  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    Not unless you program it to.

    e.g

    catch(runtime_error &e)
    {
    cout << e.what();
    }

    could be "domain_error", "logic_error" etc

    there's a few standard exceptions, beyond that you tell your classes what message to relay. eg a db class might have a db_exception which you'd use in the catch.

    catch(...) is a catch everything and keep quiet option.


  • Registered Users, Registered Users 2 Posts: 3,888 ✭✭✭ozmo


    ressem wrote:
    Not unless you program it to.

    e.g

    catch(runtime_error &e)
    {
    cout << e.what();
    }

    could be "domain_error", "logic_error" etc

    there's a few standard exceptions, beyond that you tell your classes what message to relay. eg a db class might have a db_exception which you'd use in the catch.

    catch(...) is a catch everything and keep quiet option.

    ehhh - way I've been doin it :( - just hoped there might have been some equivalent like
    catch(exception& ex)
    which might give some info without having to litter a particular troublesome bit of code with try blocks.
    ta.

    “Roll it back”



  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    You've to create your own version of exception
    is this
    http://www.codeproject.com/cpp/exception.asp
    more like it?


  • Registered Users, Registered Users 2 Posts: 3,888 ✭✭✭ozmo


    ressem wrote:
    You've to create your own version of exception
    is this
    http://www.codeproject.com/cpp/exception.asp
    more like it?

    Ah very good. I knew it must be possible somehow as visual c environment
    is able to to do it.
    Full stack trace and error trapping for general errors like memory access errors :)

    “Roll it back”



Advertisement