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/.
33 g_error_new_valist(GQuark domain,
40 error = g_new (GError, 1);
42 error->domain = domain;
44 error->message = g_strdup_vprintf (format, args);
51 * @domain: error domain
53 * @format: printf()-style format for error message
54 * @Varargs: parameters for message format
56 * Creates a new #GError with the given @domain and @code,
57 * and a message formatted with @format.
59 * Return value: a new #GError
62 g_error_new (GQuark domain,
70 g_return_val_if_fail (format != NULL, NULL);
71 g_return_val_if_fail (domain != 0, NULL);
73 va_start (args, format);
74 error = g_error_new_valist (domain, code, format, args);
81 * g_error_new_literal:
82 * @domain: error domain
84 * @message: error message
86 * Creates a new #GError; unlike g_error_new(), @message is not
87 * a printf()-style format string. Use this
88 * function if @message contains text you don't have control over,
89 * that could include printf() escape sequences.
91 * Return value: a new #GError
94 g_error_new_literal (GQuark domain,
100 g_return_val_if_fail (message != NULL, NULL);
101 g_return_val_if_fail (domain != 0, NULL);
103 err = g_new (GError, 1);
105 err->domain = domain;
107 err->message = g_strdup (message);
116 * Frees a #GError and associated resources.
120 g_error_free (GError *error)
122 g_return_if_fail (error != NULL);
124 g_free (error->message);
133 * Makes a copy of @error.
135 * Return value: a new #GError
138 g_error_copy (const GError *error)
142 g_return_val_if_fail (error != NULL, NULL);
144 copy = g_new (GError, 1);
148 copy->message = g_strdup (error->message);
156 * @domain: an error domain
157 * @code: an error code
159 * Returns %TRUE if @error matches @domain and @code, %FALSE
162 * Return value: whether @error has @domain and @code
165 g_error_matches (const GError *error,
170 error->domain == domain &&
174 #define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
175 "This indicates a bug in someone's code. You must ensure an error is NULL before it's set.\n" \
176 "The overwriting error message was: %s"
180 * @err: a return location for a #GError, or %NULL
181 * @domain: error domain
183 * @format: printf()-style format
184 * @Varargs: args for @format
186 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err must
187 * be %NULL. A new #GError is created and assigned to *@err.
190 g_set_error (GError **err,
203 va_start (args, format);
204 new = g_error_new_valist (domain, code, format, args);
210 g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
215 * @dest: error return location
216 * @src: error to move into the return location
218 * If @dest is %NULL, free @src; otherwise,
219 * moves @src into *@dest. *@dest must be %NULL.
222 g_propagate_error (GError **dest,
225 g_return_if_fail (src != NULL);
236 g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
244 * @err: a #GError return location
246 * If @err is %NULL, does nothing. If @err is non-%NULL,
247 * calls g_error_free() on *@err and sets *@err to %NULL.
250 g_clear_error (GError **err)