Thread: error trapping ??

  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