how to exit gracefully when a precondition fails

I have this code:

if (nImages == 0)
{
// terminate with error message
cout << “we’re only interested in image files, but we didn’t find any in\n”;
cout << “[” << imageFolderName << “]\n”;
exit();
}

…but it runs on past the call to exit(), apparently. Is there an alternative that will do what I want, i.e., terminate the app immediately?