Re: Output stream not closed
The stream will close automatically when it leaves the try block so yes you would have to reopen it, but it will overwrite any existing contents unless you open the file to append.
It is not normal to throw ints, but it is legal. However try..throw..catch like that within the same function is not recommended. throw is useful when you have an error to report but want to pass it back to the caller to handle. When you are planning to handle the error yourself it is best to just use boolean logic.
You might want an external function if you are likely to call it from many places:
Code:
int handle_error( std::ostream &, const std::string & errorDesc )
{
// do whatever
return 1;
}
then in your code if an error occurs call return handle_error() passing in the relevant parameters, which will also get your function to immediately return 1. (You could make the return value a parameter too if you want).
Re: Output stream not closed
Thank you very much. Actually the throws are thrown from within other functions. That was only an example to explain the what I was saying. The throws are not all inside the try block.
Thanks again!