Python Error Handling in RAD

Python provides a exception handling mechanism and propagates RAD errors by using this mechanism. RAD delivers a variety of error codes that you can handle with rad.client.ObjectError. The following example shows how to handle RAD errors.

Example 2-44 Python Language – Handling RAD Errors

import rad.client as radc
import rad.conect as radcon
import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
import logging
import sys

logging.basicConfig(filename='/tmp/example.log', level=logging.DEBUG)
with radcon.connect_unix() as rc:
    patt = radc.ADRGlobPattern({"name" : "test-0"})
    test0 = rc.get_object(zonemgr.Zone(), patt)
    print test0.name
    try:
        test0.boot(None)
    except radc.ObjectError as ex:
        error = ex.get_payload()
        if not error:
            sys.exit(1)
        if error.stdout is not None:
            logging.info(error.stdout)
        if error.stderr is not None:
            logging.info(error.stderr)
        sys.exit(1)

Note:

With ObjectError exceptions, you might get a payload. This payload is present only if your interface method or property has defined an error element, where the payload is the content of that error. If no error element for the interface method (or property) is declared, then no payload exists and error will have a value of None.