error trapping ??

This is a discussion on error trapping ?? within the C++ Programming forums, part of the General Programming Boards category; What's the quickest way to do error trapping? I remember writing just a few lines of code to trap errors ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    37

    Question error trapping ??

    What's the quickest way to do error trapping? I remember writing just a few lines of code to trap errors like:

    User enter string instead of a float or an int and vice versa

    can somebody help coz m getting tired of doing using if and while loops !

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is to check for decimal point. Another solution is to check ranges.

    Kuphryn

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Another solution is to use this
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Code:
    if(cin.fail())
    {
        cin.clear();
        cin.ignore(100, '\n');
        cout << "Doh... data type error. :P" << endl;
    }
    *should* help for strings or chars into integral types, but its not really a stream error the other way around though it may not be the type your program expected. Just use atoi or whatever to get the integral type.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    37
    hi Ronin

    Yeah i just digged out an old assignment and got it !

    thanx anyway, thanx everybody

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21