I've written a simple function that's meant to check whether files are open. In it I've written a simple exception, but should the exception throw nothing, should I put an else statement after the catch expression?
/*The function was made a template in order to
work with objects of ofstream, ifstream, and fstream type*/
template<typename f>
bool checkFileOpen(const f& file)
{
try
{
if (!file.is_open())
{
throw 1;
}
}
catch (int fileNum)
{
std::cout << "Error: File " << fileNum << " not found" << std::endl;
system("pause");
returnfalse;
}
returntrue;
}
The Questions:
(1): If the try-catch block were to throw an exception, and the returnfalse; command is reached, will the function keep running and end up returning true? Or will it stop there and carry on wherever it was called?
(2): Is it possible to put a simple else statement after the catch block, expecting that what was within the else statement would execute if no exception was thrown?