Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better log output when nodelet initialization fails #98

Open
wants to merge 3 commits into
base: noetic-devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nodelet/src/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ bool Loader::load(const std::string &name, const std::string& type, const ros::M


ROS_DEBUG("Done initing nodelet %s", name.c_str());
} catch(...) {
} catch(std::runtime_error& e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about other possible exceptions (although probably not likely)?
Maybe catch std::exception instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but in this file, std::runtime_error is caught the same way in another location. If I changed it there, I'd have to change it at the other location for the sake of consistency.

The ultimately best way would be:

try {
    //
} catch (const std::exception& e) {
    // print error with e.what()
} catch (...} {
    // print error without e.what() in case something not derived from std::exception was thrown
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed both to const std::exception& now, but without the default catch.

Impl::M_stringToNodelet::iterator it = impl_->nodelets_.find(name);
if (it != impl_->nodelets_.end())
{
impl_->nodelets_.erase(it);
ROS_DEBUG ("Failed to initialize nodelet %s", name.c_str ());
return (false);
ROS_ERROR("Failed to initialize nodelet %s: %s", name.c_str(), e.what());
return false;
}
}
return true;
Expand Down