I am using filesystem::remove function to delete a file if a button pressed. The function throw an error when the file I want to delete is used by other program. I want to use try catch functions to catch the error and to prevent the program to crash. I tried this:
bool delete_file(std::string database_name)
{
bool exception = false;
database_name += ".db";
try
{
fs::remove((path + database_name).c_str());
}
catch(...)
{
exception = true;
}
return exception;
}
but the exception is not catched. I am not very experienced with error handling and thought that the function inside try block will not be executed if error occures and it goes to catch block, in python it works so... How to make the function to return false if exeption found and true otherwise ?