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

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

Options
  • 22-02-2005 5:48pm
    #1
    Registered Users Posts: 3,867 ✭✭✭


    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 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 Posts: 3,867 ✭✭✭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 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 Posts: 3,867 ✭✭✭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