Exceptions

Overview

Robot Raconteur uses exceptions to handle errors. Robot Raconteur has a built-in set of exceptions defined by the library, and also allows custom exceptions to be defined in service definitions. See the Framework Exceptions Documentation for a full list of exceptions, and the documentation for each programming language for how they are used. All custom exceptions extend RobotRaconteurRemoteException.

Robot Raconteur can transparently pass exceptions from the service to the client (or client to service for callbacks). The following operations will transparently pass exceptions: * property get and set * function calls * objref get * pipe connect and close endpoints (for client) * callback calls (passing from client to service) * wire connect, close (for clients), peek, and poke * memory all operations

The example service definition experimental.exception_example contains a custom exception and an object with functions that will throw exceptions as an example. The service definition is shown below:

 1service experimental.exception_example
 2
 3stdver 0.10
 4
 5exception MyExampleCustomException
 6
 7object ExceptionExample
 8    function void my_exception_function1()
 9    function void my_exception_function2()
10end

The following example code demonstrates how to catch exceptions thrown by the example service:

 1# exception_example.py - Example of using exceptions in Python
 2
 3from RobotRaconteur.Client import *
 4
 5# Connect to the service
 6url = 'rr+tcp://localhost:53224/?service=exception_example'
 7c = RRN.ConnectService(url)
 8
 9# Call the functions
10
11# Catch an OperationFailedException built-in exception
12try:
13    c.my_exception_function1()
14except RR.OperationFailedException as e:
15    print("Caught OperationFailedException: " + str(e))
16
17# Catch a custom exception
18exp_type = RRN.GetExceptionType("experimental.exception_example.MyExampleCustomException", c)
19try:
20    c.my_exception_function2()
21except exp_type as e:
22    print("Caught MyExampleCustomException: " + str(e))
23
24# Catch RobotRaconteurException to catch all Robot Raconteur exceptions
25try:
26    c.my_exception_function1()
27except RR.RobotRaconteurException as e:
28    print("Caught RobotRaconteurException: " + str(e))