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

Revision history [back]

click to hide/show revision 1
initial version

I guess its use case specific, so I check what might be thrown and define it in catch: 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
}

Or 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 ", ex.what());
    }

I guess its use case specific, so I check what might be thrown and define it in catch: 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
}

Or 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 ", ex.what());
e.what());
    }

Unitl the guidelines are updated, I guess its use case specific, so I check what might be thrown and define do it in catch: 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());
    }