Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

Error reporting
[D-BUS message system public API]

Error reporting. More...

Functions

void dbus_error_init (DBusError *error)
 Initializes a DBusError structure. More...

void dbus_error_free (DBusError *error)
 Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_init(). More...

void dbus_set_error_const (DBusError *error, const char *name, const char *message)
 Assigns an error name and message to a DBusError. More...

void dbus_move_error (DBusError *src, DBusError *dest)
 Moves an error src into dest, freeing src and overwriting dest. More...

dbus_bool_t dbus_error_has_name (const DBusError *error, const char *name)
 Checks whether the error is set and has the given name. More...

dbus_bool_t dbus_error_is_set (const DBusError *error)
 Checks whether an error occurred (the error is set). More...

void dbus_set_error (DBusError *error, const char *name, const char *format,...)
 Assigns an error name and message to a DBusError. More...


Detailed Description

Error reporting.

Types and functions related to reporting errors.

In essence D-BUS error reporting works as follows:

 DBusError error;
 dbus_error_init (&error);
 dbus_some_function (arg1, arg2, &error);
 if (dbus_error_is_set (&error))
   {
     fprintf (stderr, "an error occurred: %s\n", error.message);
     dbus_error_free (&error);
   }

There are some rules. An error passed to a D-BUS function must always be unset; you can't pass in an error that's already set. If a function has a return code indicating whether an error occurred, and also a DBusError parameter, then the error will always be set if and only if the return code indicates an error occurred. i.e. the return code and the error are never going to disagree.

An error only needs to be freed if it's been set, not if it's merely been initialized.

You can check the specific error that occurred using dbus_error_has_name().


Function Documentation

void dbus_error_free DBusError   error
 

Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_init().

Parameters:
error  memory where the error is stored.

Definition at line 173 of file dbus-errors.c.

References DBusRealError::const_message, and DBusRealError::message.

dbus_bool_t dbus_error_has_name const DBusError   error,
const char *    name
 

Checks whether the error is set and has the given name.

Parameters:
error  the error
name  the name
Returns:
TRUE if the given named error occurred

Definition at line 259 of file dbus-errors.c.

References DBusError::message, and DBusError::name.

void dbus_error_init DBusError   error
 

Initializes a DBusError structure.

Does not allocate any memory; the error only needs to be freed if it is set at some point.

Parameters:
error  the DBusError.

Definition at line 150 of file dbus-errors.c.

References DBusRealError::const_message, DBusRealError::message, and DBusRealError::name.

dbus_bool_t dbus_error_is_set const DBusError   error
 

Checks whether an error occurred (the error is set).

Parameters:
error  the error object
Returns:
TRUE if an error occurred

Definition at line 286 of file dbus-errors.c.

References DBusError::message, and DBusError::name.

void dbus_move_error DBusError   src,
DBusError   dest
 

Moves an error src into dest, freeing src and overwriting dest.

Both src and dest must be initialized. src is reinitialized to an empty error. dest may not contain an existing error. If the destination is NULL, just frees and reinits the source error.

Parameters:
src  the source error
dest  the destination error or NULL

Definition at line 236 of file dbus-errors.c.

void dbus_set_error DBusError   error,
const char *    name,
const char *    format,
...   
 

Assigns an error name and message to a DBusError.

Does nothing if error is NULL.

The format may be NULL, which means a default message will be deduced from the name. If the error name is unknown to D-BUS the default message will be totally useless, though.

If no memory can be allocated for the error message, an out-of-memory error message will be set instead.

Todo:
should be called dbus_error_set()
Parameters:
error  the error.
name  the error name (not copied!!!)
format  printf-style format string.

Definition at line 312 of file dbus-errors.c.

References DBusRealError::const_message, DBusError::message, DBusRealError::message, DBusError::name, and DBusRealError::name.

void dbus_set_error_const DBusError   error,
const char *    name,
const char *    message
 

Assigns an error name and message to a DBusError.

Does nothing if error is NULL. The message may be NULL, which means a default message will be deduced from the name. If the error name is unknown to D-BUS the default message will be totally useless, though.

Todo:
should be called dbus_error_set_const()
Parameters:
error  the error.
name  the error name (not copied!!!)
message  the error message (not copied!!!)

Definition at line 200 of file dbus-errors.c.

References DBusRealError::const_message, DBusError::message, DBusRealError::message, DBusError::name, and DBusRealError::name.


Generated on Wed Jun 9 05:01:27 2004 for D-BUS by doxygen1.2.15