1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
34 g_error_new_valist(GQuark domain,
41 error = g_new (GError, 1);
43 error->domain = domain;
45 error->message = g_strdup_vprintf (format, args);
52 * @domain: error domain
54 * @format: printf()-style format for error message
55 * @Varargs: parameters for message format
57 * Creates a new #GError with the given @domain and @code,
58 * and a message formatted with @format.
60 * Return value: a new #GError
63 g_error_new (GQuark domain,
71 g_return_val_if_fail (format != NULL, NULL);
72 g_return_val_if_fail (domain != 0, NULL);
74 va_start (args, format);
75 error = g_error_new_valist (domain, code, format, args);
82 * g_error_new_literal:
83 * @domain: error domain
85 * @message: error message
87 * Creates a new #GError; unlike g_error_new(), @message is not
88 * a printf()-style format string. Use this
89 * function if @message contains text you don't have control over,
90 * that could include printf() escape sequences.
92 * Return value: a new #GError
95 g_error_new_literal (GQuark domain,
101 g_return_val_if_fail (message != NULL, NULL);
102 g_return_val_if_fail (domain != 0, NULL);
104 err = g_new (GError, 1);
106 err->domain = domain;
108 err->message = g_strdup (message);
117 * Frees a #GError and associated resources.
121 g_error_free (GError *error)
123 g_return_if_fail (error != NULL);
125 g_free (error->message);
134 * Makes a copy of @error.
136 * Return value: a new #GError
139 g_error_copy (const GError *error)
143 g_return_val_if_fail (error != NULL, NULL);
145 copy = g_new (GError, 1);
149 copy->message = g_strdup (error->message);
157 * @domain: an error domain
158 * @code: an error code
160 * Returns %TRUE if @error matches @domain and @code, %FALSE
163 * Return value: whether @error has @domain and @code
166 g_error_matches (const GError *error,
171 error->domain == domain &&
175 #define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
176 "This indicates a bug in someone's code. You must ensure an error is NULL before it's set.\n" \
177 "The overwriting error message was: %s"
181 * @err: a return location for a #GError, or %NULL
182 * @domain: error domain
184 * @format: printf()-style format
185 * @Varargs: args for @format
187 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err must
188 * be %NULL. A new #GError is created and assigned to *@err.
191 g_set_error (GError **err,
204 va_start (args, format);
205 new = g_error_new_valist (domain, code, format, args);
211 g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
216 * @dest: error return location
217 * @src: error to move into the return location
219 * If @dest is %NULL, free @src; otherwise,
220 * moves @src into *@dest. *@dest must be %NULL.
223 g_propagate_error (GError **dest,
226 g_return_if_fail (src != NULL);
237 g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
245 * @err: a #GError return location
247 * If @err is %NULL, does nothing. If @err is non-%NULL,
248 * calls g_error_free() on *@err and sets *@err to %NULL.
251 g_clear_error (GError **err)