Error reporting
[D-Bus low-level public API]

Error reporting. More...

Functions

void dbus_error_init (DBusError *error)
 Initializes a DBusError structure.
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().
void dbus_set_error_const (DBusError *error, const char *name, const char *message)
 Assigns an error name and message to a DBusError.
void dbus_move_error (DBusError *src, DBusError *dest)
 Moves an error src into dest, freeing src and overwriting dest.
dbus_bool_t dbus_error_has_name (const DBusError *error, const char *name)
 Checks whether the error is set and has the given name.
dbus_bool_t dbus_error_is_set (const DBusError *error)
 Checks whether an error occurred (the error is set).
void dbus_set_error (DBusError *error, const char *name, const char *format,...)
 Assigns an error name and message to a DBusError.

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 174 of file dbus-errors.c.

References DBusRealError::const_message, dbus_error_init(), dbus_free(), DBusRealError::message, DBusRealError::name, and NULL.

Referenced by _dbus_keyring_new_homedir(), and dbus_move_error().

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 261 of file dbus-errors.c.

References _dbus_assert, _dbus_string_equal(), _dbus_string_init_const(), FALSE, DBusError::message, DBusError::name, and NULL.

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 151 of file dbus-errors.c.

References _dbus_assert, DBusRealError::const_message, DBusRealError::message, DBusRealError::name, NULL, and TRUE.

Referenced by _dbus_keyring_new_homedir(), dbus_error_free(), and dbus_move_error().

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 288 of file dbus-errors.c.

References _dbus_assert, FALSE, DBusError::message, DBusError::name, and NULL.

Referenced by dbus_address_unescape_value(), and dbus_parse_address().

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 238 of file dbus-errors.c.

References dbus_error_free(), and dbus_error_init().

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.

Parameters:
error the error.
name the error name
format printf-style format string.

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

References _dbus_assert, _dbus_strdup(), _dbus_string_append(), _dbus_string_append_printf_valist(), _dbus_string_free(), _dbus_string_init(), _dbus_string_steal_data(), DBusRealError::const_message, dbus_free(), FALSE, DBusError::message, DBusRealError::message, DBusError::name, DBusRealError::name, and NULL.

Referenced by _dbus_babysitter_set_child_exit_error(), _dbus_become_daemon(), _dbus_change_identity(), _dbus_check_dir_is_private_to_user(), _dbus_close(), _dbus_connect_tcp_socket(), _dbus_connect_unix_socket(), _dbus_create_directory(), _dbus_create_file_exclusively(), _dbus_delete_directory(), _dbus_delete_file(), _dbus_directory_get_next_file(), _dbus_directory_open(), _dbus_file_get_contents(), _dbus_full_duplex_pipe(), _dbus_is_console_user(), _dbus_keyring_new_homedir(), _dbus_listen_tcp_socket(), _dbus_listen_unix_socket(), _dbus_message_iter_get_args_valist(), _dbus_read_credentials_unix_socket(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_tcp_socket(), _dbus_set_fd_nonblocking(), _dbus_spawn_async_with_babysitter(), _dbus_stat(), _dbus_string_save_to_file(), _dbus_transport_new_for_domain_socket(), _dbus_transport_new_for_tcp_socket(), _dbus_transport_open(), _dbus_user_at_console(), _dbus_user_database_get_groups(), _dbus_user_database_lookup(), _dbus_user_database_lookup_group(), _dbus_write_pid_file(), dbus_parse_address(), dbus_server_listen(), dbus_set_error_from_message(), dbus_signature_validate(), and dbus_signature_validate_single().

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.

Parameters:
error the error.
name the error name (not copied!!!)
message the error message (not copied!!!)

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

References _dbus_assert, DBusRealError::const_message, DBusError::message, DBusRealError::message, DBusError::name, DBusRealError::name, NULL, and TRUE.

Referenced by _dbus_keyring_get_best_key(), and _dbus_keyring_new_homedir().


Generated on Wed Jan 3 04:58:29 2007 for D-Bus by  doxygen 1.4.7