1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5
* Bertrand Guiheneuf <bertrand@helixcode.com>
7
* Copyright 1999-2003 Ximian, Inc. (www.ximian.com)
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of version 2 of the GNU Lesser General Public
11
* License as published by the Free Software Foundation.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32
#include <glib/gi18n-lib.h>
34
#include <libedataserver/e-memory.h>
36
#include "camel-debug.h"
37
#include "camel-exception.h"
39
/* dont turn this off */
44
* camel_exception_new: allocate a new exception object.
46
* Create and returns a new exception object.
48
* Returns the newly allocated exception object
51
camel_exception_new (void)
55
ex = g_slice_new (CamelException);
58
/* set the Exception Id to NULL */
59
ex->id = CAMEL_EXCEPTION_NONE;
65
* camel_exception_init:
66
* @ex: a #CamelException
68
* Init an exception. This routine is mainly useful when using a
69
* statically allocated exception.
72
camel_exception_init (CamelException *ex)
76
/* set the Exception Id to NULL */
77
ex->id = CAMEL_EXCEPTION_NONE;
82
* camel_exception_clear:
83
* @ex: a #CamelException
85
* Clear an exception, that is, set the exception ID to
86
* #CAMEL_EXCEPTION_NONE and free the description text. If the
87
* exception is %NULL, this funtion just returns.
90
camel_exception_clear (CamelException *exception)
96
g_free (exception->desc);
97
exception->desc = NULL;
98
exception->id = CAMEL_EXCEPTION_NONE;
102
* camel_exception_free:
103
* @ex: a #CamelException
105
* Free an exception object. If the exception is %NULL, nothing is
106
* done, the routine simply returns.
109
camel_exception_free (CamelException *exception)
115
g_free (exception->desc);
117
g_slice_free (CamelException, exception);
121
* camel_exception_set: set an exception
122
* @ex: a #CamelException
124
* @desc: textual description of the exception
126
* Set the value of an exception. The exception id is
127
* a unique number representing the exception. The
128
* textual description is a small text explaining
129
* what happened and provoked the exception.
131
* When @ex is %NULL, nothing is done, this routine
135
camel_exception_set (CamelException *ex, ExceptionId id, const char *desc)
137
if (camel_debug("exception"))
138
printf("CamelException.set(%p, %u, '%s')\n", ex, id, desc);
142
if (desc != ex->desc) {
144
ex->desc = g_strdup (desc);
149
* camel_exception_setv: set an exception
150
* @ex: a #CamelException
152
* @format: format of the description string. The format string is
153
* used as in printf().
155
* Set the value of an exception. The exception id is
156
* a unique number representing the exception. The
157
* textual description is a small text explaining
158
* what happened and provoked the exception.
159
* In this version, the string is created from the format
160
* string and the variable argument list.
163
* camel_exception_setv (ex, ..., camel_exception_get_description (ex), ...);
165
* When @ex is %NULL, nothing is done, this routine
169
camel_exception_setv (CamelException *ex, ExceptionId id, const char *format, ...)
174
va_start(args, format);
175
desc = g_strdup_vprintf (format, args);
178
if (camel_debug("exception"))
179
printf("CamelException.setv(%p, %u, '%s')\n", ex, id, desc);
192
* camel_exception_xfer:
193
* @ex_dst: Destination exception object
194
* @ex_src: Source exception object
196
* Transfer the content of an exception from an exception object to
197
* another. The destination exception receives the id and the
198
* description text of the source exception.
201
camel_exception_xfer (CamelException *ex_dst,
202
CamelException *ex_src)
204
if (ex_src == NULL) {
205
w(g_warning ("camel_exception_xfer: trying to transfer NULL exception to %p\n", ex_dst));
209
if (ex_dst == NULL) {
210
/* must have same side-effects */
211
camel_exception_clear (ex_src);
216
g_free (ex_dst->desc);
218
ex_dst->id = ex_src->id;
219
ex_dst->desc = ex_src->desc;
222
ex_src->id = CAMEL_EXCEPTION_NONE;
226
* camel_exception_get_id:
227
* @ex: a #CamelException
229
* Get the id of an exception.
231
* Returns the exception id (#CAMEL_EXCEPTION_NONE will be returned if
232
* @ex is %NULL or unset)
235
camel_exception_get_id (CamelException *ex)
240
w(g_warning ("camel_exception_get_id called with NULL parameter."));
242
return CAMEL_EXCEPTION_NONE;
246
* camel_exception_get_description:
247
* @ex: a #CamelException
249
* Get the exception description text.
251
* Returns the exception description text (%NULL will be returned if
252
* @ex is %NULL or unset)
255
camel_exception_get_description (CamelException *ex)
262
w(g_warning ("camel_exception_get_description called with NULL parameter."));
264
return ret ? ret : (_("No description available"));