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/.
30 g_error_new_valist(GQuark domain,
37 error = g_new (GError, 1);
39 error->domain = domain;
41 error->message = g_strdup_vprintf (format, args);
48 * @domain: error domain
50 * @format: <function>printf()</function>-style format for error message
51 * @Varargs: parameters for message format
53 * Creates a new #GError with the given @domain and @code,
54 * and a message formatted with @format.
56 * Return value: a new #GError
59 g_error_new (GQuark domain,
67 g_return_val_if_fail (format != NULL, NULL);
68 g_return_val_if_fail (domain != 0, NULL);
70 va_start (args, format);
71 error = g_error_new_valist (domain, code, format, args);
78 * g_error_new_literal:
79 * @domain: error domain
81 * @message: error message
83 * Creates a new #GError; unlike g_error_new(), @message is not
84 * a <function>printf()</function>-style format string. Use this
85 * function if @message contains text you don't have control over,
86 * that could include <function>printf()</function> escape sequences.
88 * Return value: a new #GError
91 g_error_new_literal (GQuark domain,
97 g_return_val_if_fail (message != NULL, NULL);
98 g_return_val_if_fail (domain != 0, NULL);
100 err = g_new (GError, 1);
102 err->domain = domain;
104 err->message = g_strdup (message);
113 * Frees a #GError and associated resources.
117 g_error_free (GError *error)
119 g_return_if_fail (error != NULL);
121 g_free (error->message);
130 * Makes a copy of @error.
132 * Return value: a new #GError
135 g_error_copy (const GError *error)
139 g_return_val_if_fail (error != NULL, NULL);
141 copy = g_new (GError, 1);
145 copy->message = g_strdup (error->message);
153 * @domain: an error domain
154 * @code: an error code
156 * Returns %TRUE if @error matches @domain and @code, %FALSE
159 * Return value: whether @error has @domain and @code
162 g_error_matches (const GError *error,
167 error->domain == domain &&
171 #define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
172 "This indicates a bug in someone's code. You must ensure an error is NULL before it's set.\n" \
173 "The overwriting error message was: %s"
177 * @err: a return location for a #GError, or %NULL
178 * @domain: error domain
180 * @format: <function>printf()</function>-style format
181 * @Varargs: args for @format
183 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err must
184 * be %NULL. A new #GError is created and assigned to *@err.
187 g_set_error (GError **err,
200 va_start (args, format);
201 new = g_error_new_valist (domain, code, format, args);
207 g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
212 * @dest: error return location
213 * @src: error to move into the return location
215 * If @dest is %NULL, free @src; otherwise,
216 * moves @src into *@dest. *@dest must be %NULL.
219 g_propagate_error (GError **dest,
222 g_return_if_fail (src != NULL);
233 g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
241 * @err: a #GError return location
243 * If @err is %NULL, does nothing. If @err is non-%NULL,
244 * calls g_error_free() on *@err and sets *@err to %NULL.
247 g_clear_error (GError **err)