Boost logo

Boost Users :

Subject: Re: [Boost-users] [filesystem] Hoe to depress boost::filesystem::basic_directory_iterator constructor?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-04-29 10:42:32


And of course you can catch these some layers higher and transform these
exceptions into the needed ones.

e.g.

void scan_directories(fs::path const& path)
{
   //....
}

void do_smth()
{
  //...
}

void foo()
{
   scan_directories("c:“);
}

void rethow_my_exception(std::exception const& e)
{
   //could be
    throw std::logic_error(std::string("execution failed:
").append(e.what()));
}

//you can even overload rethrow_my_exception for different formattings

void bar()
{
     try
     {
         foo();
         do_smth();
     }
     catch(std::exception const& e)
     {
         rethrow_my_exception(e);
     }
}

As you see, there are no limits.

Good Luck,
Ovanes

On Wed, Apr 29, 2009 at 4:26 PM, Ovanes Markarian <om_boost_at_[hidden]>wrote:

>
>
> On Wed, Apr 29, 2009 at 3:20 PM, Max <more4less_at_[hidden]> wrote:
>
>> Hello Ovanes,
>>
>> Thanks for your reply.
>>
>> You means like this?
>>
>> catch ( const fs::basic_filesystem_error<fs::path>& e )
>> {
>> // transform e.what() to a new string by search and replace
>> // rethrow an exception
>> }
>>
>> That would be ok for this single case. But who knows if there's other
>> similar cases that need this similar hand-written code processing?
>> I want to depress the similar message in a uniform way.
>
>
> You can also catch more general exceptions like:
> boost::system_error or std::runtime_error or std::exception (or any other
> unknown exception via catch(...) )
>
> And handle them...
>
> Regards,
> Ovanes
>
>



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