[filesystem][system] Usage guideline request

View: New views
3 Messages — Rating Filter:   Alert me  

[filesystem][system] Usage guideline request

by Andrey Semashev-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm updating our software from Boost 1.33 to 1.40 and one of the major
issues I encountered is using exceptions from Boost.Filesystem. The
exception basic_filesystem_error has changed its interface in a breaking
way, as it now relies on Boost.System error codes. I'm not aware of
whether this change has been announced properly and the API deprecation
period has been offered. And that is actually not what bothers me mostly.

The 1.33 version of Boost.Filesystem offered a number of unified error
codes that our code used to react accordingly. For example, there were
error codes out_of_space_error, already_exists_error, which were used on
any platform supported by Boost.Filesystem. Now, with Boost.System in
place, there are at least three sets of errors: system::errc,
system::windows_error and system::linux_error, although, I assume, the
latter is an addition to system::errc. In order to check for the older
out_of_space_error I now have to write something like this:

   catch (basic_filesystem_error& e)
   {
     if (
       e.code() == system::errc::make_error_code(
         system::errc::no_space_on_device)
   #if defined(WIN32)
       || e.code() == system::windows_error::make_error_code(
         system::windows_error::disk_full)
   #endif
     )
     {
       // out_of_space_error
     }
   }

Is this the right way to do this? Is there a portable way to do it?

I tried to find a better way in the Boost.System documentation, but was
highly disappointed as there is virtually no documentation at all. Also,
no examples available for this library. I wonder how this library passed
the review in the first place.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Re: [filesystem][system] Usage guideline request

by Eric MALENFANT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrey Semashev wrote:

>    catch (basic_filesystem_error& e)
>    {
>      if (
>        e.code() == system::errc::make_error_code(
>          system::errc::no_space_on_device)
>    #if defined(WIN32)
>        || e.code() == system::windows_error::make_error_code(
>          system::windows_error::disk_full)
>    #endif
>      )
>      {
>        // out_of_space_error
>      }
>    }
>
> Is this the right way to do this? Is there a portable way to do it?
>

My understanding of
http://www.boost.org/doc/libs/1_40_0/libs/system/doc/reference.html#Non-
member-functions is that error_category.equivalent() is there to
abstract this. operator== is overloaded on error_code and
error_condition to perform that equivalence check, so this should do
what you want:

  catch (const basic_filesystem_error& e){
        if (e == make_error_condition(posix_error::no_space_on_device)){
      //...
      }
  }
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Re: [filesystem][system] Usage guideline request

by Andrey Semashev-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eric MALENFANT wrote:

> Andrey Semashev wrote:
>> Is this the right way to do this? Is there a portable way to do it?
>>
>
> My understanding of
> http://www.boost.org/doc/libs/1_40_0/libs/system/doc/reference.html#Non-
> member-functions is that error_category.equivalent() is there to
> abstract this. operator== is overloaded on error_code and
> error_condition to perform that equivalence check, so this should do
> what you want:
>
>   catch (const basic_filesystem_error& e){
> if (e == make_error_condition(posix_error::no_space_on_device)){
>       //...
>       }
>   }

Thanks, looks like this is what I need.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost