Error Handling
Error handling in the Parallels Python API is done through the use of exceptions that are caught in
try
blocks and handled in
except
blocks. All methods in the API throw the
prlsdkapi.PrlSDKError
exception. The
PrlSDKError
object itself contains the error message. To obtain the error code, examine the
prlsdkapi.PrlSDKError.error_code
argument. The error code can be evaluated against standard Parallels API errors, which can be found in the
prlsdkapi.prlsdk.errors
module. The most common error codes are
PRL_ERR_SUCCESS
,
PRL_ERR_INVALID_ARG
,
PRL_ERR_OUT_OF_MEMORY
. For the complete list of errors, see the
prlsdkapi.prlsdk.errors
module documentation or the
Parallels Python API Reference
guide.
The following code sample illustrates the exception handling:
try:
# The call returns a prlsdkapi.Result object on success.
result = server.login(host, user, password, '', 0, 0, security_level).wait()
except prlsdkapi.PrlSDKError, e:
print "Login error: %s" % e
print "Error code: " + str(e.error_code)
raise Halt
|