Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROS_INFO_STREAM does not print

Tags:

c++

ros

I'm trying to use ROS_INFO_STREAM inside an imbricated try...catch but I only have the top-level output

Here's a minimal bunch of code:

void failure()
{
    try
    {
      // throw std::length_error
      std::string("abc").substr(10);                    
    }
    catch (...)
    {
      ROS_ERROR_STREAM("ROS failure()");          // print OK
      std::cout << "cout failure()" << std::endl; // print OK
      throw; // re-throw the exception
    }
}


int main()
{
  try
  {
    ROS_ERROR_STREAM("ROS calling"); // print OK
    failure(); // will throw
  }
  catch (...)
  {
    ROS_ERROR_STREAM("ROS call function"); // <-- NO print
    std::cout << "cout call function" << std::endl; // print OK
  }

  return 0;
}

output:

ROS calling
ROS failure()
cout failure()
cout call function

My guess would be that ROS_ERROR_STREAM looks buffered but as an error output it shouldn't be.

I'm running ROS Groovy

like image 974
Zermingore Avatar asked Oct 30 '22 18:10

Zermingore


1 Answers

All the macros in rosconsole stop working when ros::shutdown() has been called somewhere in the ROS node.

I can imagine that something like that happens to you: the catch block in the main is probably reached after an error which calls automatically the ros::shutdown() function.

If you would like to maintain the same output format like the one provided by ROS macros, you can use a simple code like this one, but forget to get the code highlighted with colors or other stuff:

std::cout << "[ INFO] [" << ros::Time::now() << "]: main catch" << std::endl;
like image 188
alextoind Avatar answered Nov 15 '22 06:11

alextoind