Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 22-02-2005 04:48PM
    #1
    Registered Users, Registered Users 2 Posts: 3,893 ✭✭✭


    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, Paid Member Posts: 2,427 ✭✭✭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,893 ✭✭✭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, Paid Member Posts: 2,427 ✭✭✭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,893 ✭✭✭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