[ros-users] Throwing exceptions in services (Python vs. C++)

Ken Conley kwc at willowgarage.com
Wed Dec 7 21:26:24 UTC 2011

On Tue, Dec 6, 2011 at 9:35 AM, Dirk Thomas <mail at dirk-thomas.net> wrote:
> I looked into the issue posted one month ago, that thrown exceptions in
> service-servers are not passed to the service-clients.
> This is at least the case for roscpp - in rospy (and roslisp) it is
> implemented already.
> After some "warm-up" with the respective code-parts I came up with a small
> patch (see attached - this is not meant to be committed!!!).
> I have tested the following scenario:
> - add_two_ints_server (c++, modified to throw a runtime-exception)
> called by
> - add_two_ints_client (py)
> Usually the serialization of the response (generated in
> "serializeServiceResponse") contains the following content: ok-flag,
> msg-size, msg-payload.
> But in order to make it compatible with rospy the response must contain
> only: ok-flag, msg-payload.
> Before looking at the client part of the roscpp service handling (to also
> output the received error string) I would like to clarify the serialization
> format.
> Is there any specification how a service response must look like (even in
> the case of "ok" being false)?

If the ok byte is true, it must be followed by a serialized string
(same length + bytes format that ROS messages use for serializing

If the ok byte is false, it must be followed by the service response message.

 - Ken

> Is the current implementation of rospy/roslisl "correct" or should it be
> altered to also contain the message size?
> Dirk
> On 08.11.2011 17:31, Thibault Kruse wrote:
>> I raised this a while ago here:
>> https://code.ros.org/trac/ros/ticket/3590
>> but i could not provide a patch myself.
>> With a patch the ticket may get more attention.
>> It should not be too difficult technically (I implemented it for roslisp
>> as for
>> rospy in https://code.ros.org/trac/ros/ticket/3594), but I found it too
>> hard
>> to dig into the roscpp code.
>> On 11/08/2011 05:13 PM, Dirk Thomas wrote:
>>> Hi,
>>> we are using ROS services implemented in Python as well as in C++.
>>> We found one significant difference in both implementations (which makes
>>> debugging more difficult):
>>> This is when a service throws an exception.
>>> In both languages a message is printed on the server's console.
>>> In Python the string of the exception is also passed to the client.
>>> But in C++ the exception is NOT passed to the client.
>>> Is there a technical reason why the C++-ServiceCallback does not pass the
>>> exception message?
>>> If not could this be added?
>>> Regards,
>>> Dirk
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users

More information about the ros-users mailing list