Boost logo

Boost :

From: Martin Adrian (adrianm_at_[hidden])
Date: 2006-04-14 13:48:13

Angus Leeming <angus.leeming <at>> writes:

> If I understand correctly, the idiom to check whether a directory exists
> using Boost.Filesystem is
> if (fs::exists(path) && fs::is_directory(path))
> Under normal conditions the code above shouldn't throw, right?

Welcome to the wonderful world of filesystem exceptions. Your code will throw
on many conditions. Some I know from the top of my head are (on windows):
1. path is a system file like pagefile.sys
2. the user don't have access to an element in the path.

I have tried to point out several times that filesystem operations can and
will throw. Production code without try/catch around ALL filesystem operations
will cause problems (and don't assume that the catch statement should only
handle racing and filesystem corruption exceptions).

I think the documentation should have big red letters saying:
- Never use any filesystem operation in production code without proper
try/catch guards (or use the non-throwing versions in 1.34).
- Never assume that an operations "will not throw under normal conditions"
because it will.

A good way to test your code is to run the application as a non-administrator
and enter "c:\" and "C:\pagefile.sys" as test paths.

Boost list run by bdawes at, gregod at, cpdaniel at, john at