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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With