[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 CatchError

error.CatchError is an object which can be used as an error handler. It collects an error matching any of the specified types, which can be retrieved later. If several errors occur, only the last one is remembered.

Class: CatchError ( *errors )

Create a new error handler object. Initialize by providing all error classes you are interested in as arguments. If no error classes are provided at all, this means that all errors will be considered.

Pass the error.CatchError object as the onerror parameter to X object methods. If these methods generated any errors matching the ones specified, it can be retrieved with the following functions:

Method on CatchError: get_error ( )

Return the last error object caught, or None if no matching errors has occured.

Method on CatchError: get_request ( )

Return the request object for the last error caught, or None if no matching errors has occured.

error.CatchError objects can be reused:

Method on CatchError: reset ( )

Forget any caught error.

Since the X protocol is mostly asynchronous any error we’re watching for might not have been received when we call get_error. To make sure that the request has been processed by the server and any error generated has been received by the Xlib, we must synchronize with the server.

An example of using error.CatchError:

# Resize and the foo window
# If it has been destroyed since we looked at it the last time,
# reset variable foo to None

# Create a error handler for BadWindow errors
ec = error.CatchError(error.BadWindow)

# Perform the operation
foo.configure(width = 100, height = 200, onerror = ec)

# Sync communication with server

# And check if there was any error
if ec.get_error():
    foo = None

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on September 16, 2020 using texi2html 5.0.