8
#include "camel-imapx-exception.h"
12
static pthread_key_t handler_key = 0;
14
void camel_exception_setup(void)
16
pthread_key_create(&handler_key, NULL);
20
camel_exception_try(struct _CamelExceptionEnv *env)
22
struct _CamelExceptionEnv *handler;
24
handler = pthread_getspecific(handler_key);
25
env->parent = handler;
29
pthread_setspecific(handler_key, handler);
33
camel_exception_throw_ex(CamelException *ex)
35
struct _CamelExceptionEnv *env;
37
printf("throwing exception '%s'\n", ex->desc);
39
env = pthread_getspecific(handler_key);
42
pthread_setspecific(handler_key, env->parent);
43
longjmp(env->env, ex->id);
45
fprintf(stderr, "\nUncaught exception: %s\n", ex->desc);
46
/* we just crash and burn, this is a code problem */
47
/* we dont use g_assert_not_reached() since its not a noreturn function */
53
camel_exception_throw(gint id, gchar *fmt, ...)
58
ex = camel_exception_new();
61
ex->desc = g_strdup_vprintf(fmt, ap);
64
camel_exception_throw_ex(ex);
68
camel_exception_drop(struct _CamelExceptionEnv *env)
70
pthread_setspecific(handler_key, env->parent);
74
camel_exception_done(struct _CamelExceptionEnv *env)
76
pthread_setspecific(handler_key, env->parent);
77
if (env->ex != NULL) {
78
camel_exception_free(env->ex);