diff --git a/lcm/drake_lcm.cc b/lcm/drake_lcm.cc index 7eb5de839004..4cb93ef18d29 100644 --- a/lcm/drake_lcm.cc +++ b/lcm/drake_lcm.cc @@ -61,7 +61,10 @@ class DrakeLcm::Impl { // Create the native instance only after all other checks are finished. lcm_ = ::lcm_create(lcm_url_.c_str()); if (lcm_ == nullptr) { - throw std::runtime_error("Failure on lcm_create()"); + // The initialization failed and printed a console warning. Create + // a dummy object instead (to at least have something non-null). + lcm_ = ::lcm_create("memq://"); + DRAKE_THROW_UNLESS(lcm_ != nullptr); } } diff --git a/lcm/test/drake_lcm_test.cc b/lcm/test/drake_lcm_test.cc index 5ada76e2ca40..6d5c7f695ef0 100644 --- a/lcm/test/drake_lcm_test.cc +++ b/lcm/test/drake_lcm_test.cc @@ -77,6 +77,12 @@ TEST_F(DrakeLcmTest, CustomUrlTest) { EXPECT_EQ(dut_->get_lcm_url(), kUdpmUrl); } +TEST_F(DrakeLcmTest, BadUrlTest) { + // At the moment, invalid URLs print to the console but do not throw. + // We probably want to revisit this as some point (to fail-fast). + EXPECT_NO_THROW(DrakeLcm("no-such-scheme://foo")); +} + TEST_F(DrakeLcmTest, DeferThreadTest) { DrakeLcmParams params; params.lcm_url = kUdpmUrl;