It only depends on what the return value of this function means.
If the case of exception means false then return false, it it means true then return true.
If it depends upon the exception code/error number/or something similar - then it is up to you to choose what to return: true or false...
It only depends on what the return value of this function means.
If the case of exception means false then return false, it it means true then return true.
If it depends upon the exception code/error number/or something similar - then it is up to you to choose what to return: true or false...
The problem is there is no way to decide whether it should return true or false when an exception is thrown. For example, when we call the statement "if thing one is not done" , it may throw an exception. So in this case, should I return true or false in the catch clause? This is really confusing...
More typically you'd throw in the function and put the try/catch in the function that calls it. That way you'd know if it returned legitimately or threw the exception.
You can update this scheme: instead of doing "if-return; if-return", you can go for the "if{if{if{ifi{}}}}" scheme. You can replace the intermediate "return return_val" with "goto end;".
Regardless of what you are doing, the scheme of "update your return value as you go" is pretty to use. Its not the most efficient, but more often than not, it makes coding really easy.
Is your question related to IO?
Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Bookmarks