Time::findInstance cannot distinguish between failure and success
Currently with the following type of code:
fileName inst =
(
runTime.findInstance
(
polyMesh::meshSubDir,
"some-file",
IOobject::READ_IF_PRESENT
)
);
It will return "constant"
even if that particular file cannot be found. This means we need an additional code
Foam::isFile(inst/polyMesh::meshSubDir/"some-file")
To check if we have a false positive.
One thought was some extra magic, for example:
fileName inst =
(
runTime.findInstance
(
polyMesh::meshSubDir,
"some-file",
IOobject::READ_IF_PRESENT,
"#magic-code#" // This is actually the stop instance, but give it some invalid name.
)
);
which would signal the internal logic to return an empty fileName on failure. The alternative would be to use MUST_READ
within a try/catch block, but that is not particularly attractive either.
Edited by Mark OLESEN