
Peter Dimov wrote:
Reece Dunn wrote:
what happens if you have a class called shared_data that uses shmem, and use it like this:
shared_data data;
int main() { return 0; }
If this throws an exception, your application will crash and it could be difficult to determine why.
This is true for all classes. It doesn't matter whether shared_data uses shmem or not.
True, but we were discussing shmem and making it throw an exception if allocation fails. Throwing exceptions does make error handling easier in that the error reporting can be done in one place, but you have to be more careful about how you use classes that can throw. You could write my example as: class shared_data { boost::shared_ptr< shmem > shared; public: shared_data() { try { ... } catch( shmem_exception & ) { report_error_and_exit(); } catch( std::bad_alloc & ) { report_error_and_exit(); } } }; so you wouldn't need to have an error policy. This would work for other cases like this, not just using shmem. - Reece