@@ -122,17 +122,30 @@ std::shared_ptr<Engine> Stream::open(const std::string& name, Mode mode)
122122 throw UnknownOpenModeException (XBT_THROW_POINT, mode_to_str (mode));
123123
124124 // Only the first Actor calling Stream::open has to create the corresponding Engine and Transport method.
125- // Hence, we use a critical section.
125+ // Hence, we use a critical section. The creation of a FileEngine can raise an exception in the critical section
126+ // which requires special handling.
127+ bool got_exception = false ;
128+ std::string exception_msg;
129+
126130 dtl_->lock ();
127131 if (not engine_) {
128132 if (engine_type_ == Engine::Type::Staging) {
129133 engine_ = std::make_shared<StagingEngine>(name, this );
134+ engine_->create_transport (transport_method_);
130135 } else if (engine_type_ == Engine::Type::File) {
131- engine_ = std::make_shared<FileEngine>(name, this );
136+ try {
137+ engine_ = std::make_shared<FileEngine>(name, this );
138+ engine_->create_transport (transport_method_);
139+ } catch (IncorrectPathDefinitionException e) {
140+ got_exception = true ;
141+ exception_msg = std::string (e.what ());
142+ }
132143 }
133- engine_->create_transport (transport_method_);
134144 }
135145 dtl_->unlock ();
146+ // Check if an exception has been raised and caugth while creating a FileEngine. If yes, throw it again.
147+ if (got_exception)
148+ throw IncorrectPathDefinitionException (XBT_THROW_POINT, exception_msg);
136149
137150 while (not engine_) {
138151 XBT_DEBUG (" %s waits for the creation of the engine" , sg4::this_actor::get_cname ());
0 commit comments