On 8/19/07, mano M <[EMAIL PROTECTED]> wrote:

>   I am reading input as integer using scanf in C++ .I want throw runtime 
> error ,if user enters character instead of number .Is it possible through try 
> catch?Any other possibilities?

1) You don't need to use scanf in C++, you can use cin

2) You should read all data in as a string (preferably an ANSI C++
string and not a char * ) and then validate the data, converting as
necessary to the appropriate data type.

3) I personally don't like to use try-catch to handle data input
errors, you should use proper data validation. try-catch should be
used for exceptional situations, like disk out of space or a network
socket has closed upexpectedly or something along those lines.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to