ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

In general: How to catch subscription errors?

asked 2016-02-05 16:03:09 -0500

user23fj239 gravatar image

updated 2016-02-18 08:39:50 -0500

How do i catch errors from subscribers, or even better in general. Originally I tried to catch only subscription errors but as I moved on how to do catch ros exceptions in general as its done in c++ via (...)
e.g. InvalidNameException & ConflictingSubscriptionException

try{  for (unsigned i=0; i<strVec.size(); i++){

    //subscribe stuff
}
} catch (...)
    { //how to catch here, like e.what() in c++
        exit(1);
    }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-07-28 14:28:16 -0500

user23fj239 gravatar image

updated 2016-08-17 02:12:45 -0500

Unitl the guidelines are updated, I do it like so: e.g. tf can throw these, so I check for:

try
{
    // lookupTransform of tf
}
catch ( const tf2::TransformException& e )
{
    // handle custom exception
}
catch ( const tf2::LookupException& e )
{
    // handle custom exception
}
catch ( const tf2::ConnectivityException& e )
{
    // standard exceptions
}
catch ( ... )
{
    // everything else
}

In general simply by this, because

All of roscpp's exceptions inherit from a common ros::Exception base class.

   try
    {
        // throws something
    }
    catch ( ros::Exception &e )
    {
     ROS_ERROR("Error occured: %s ", e.what());
    }
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-02-05 16:03:09 -0500

Seen: 4,442 times

Last updated: Aug 17 '16