Boost logo

Boost Users :

Subject: [Boost-users] [boost.filesystem v3] recursive_directory_iterator throws unexpectedly
From: Tan, Tom (Shanghai) (TTan_at_[hidden])
Date: 2010-07-28 03:52:14


In boost::filesystem v3, while it's possible to choose a no-throw
version of recursive_directory_iterator by passing an
boost::system::error_code object to its constructor, like this:

                                  boost::system::error_code m_ec;

                                  for ( recursive_directory_iterator
itr(root, m_ec), end_itr; itr != end_itr; ++itr)

 

However, because in the implementation of the
recursive_directory_iterator::increment(), directory_iterator is always
constructed with the throw version, it would cause exception throws
during the for-loop while accessing folders like \System Volume
Information on Windows:

    void increment()

    {

      BOOST_ASSERT(m_imp.get() && "increment of end
recursive_directory_iterator");

      m_imp->increment(0);

      if (m_imp->m_stack.empty()) m_imp.reset(); // done, so make end
iterator

}

 

Where m_imp is an object of recur_dir_itr_imp:

    void recur_dir_itr_imp::increment(system::error_code* ec)

    // ec == 0 means throw on error

{

...

}

 

As it's not possible to catch this exception within the for-loop and
continue the loop, it greatly limits the use of
recursive_directory_iterator. With rough check, V2 does not seem to have
this problem. Is this a bug or change on purpose? I personally would
expect the directory_iterator to behave the same as
recursive_directory_iterator in this case.

 

Regards,

Tom

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net