exception.h
4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* \file scot/exception.h
* \author Georg Steffers <georg@steffers.org>
* \brief The user interface to exception handling.
*
* This describes the macros TRY, CATCH, THROW and EXC.
*
* Copyright (C)2006 Georg Steffers <georg@steffers.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include <setjmp.h>
#include "excenv_t.h"
#include "exception_t.h"
#include <scot/thread.h>
#ifdef USE_THREADS
# define EXC_INIT threaded_exc_init
#else
# define EXC_INIT exc_init
#endif /* USE_THREADS */
/**
* \pre None
* \return Nothing
* \post a current exception environment exists.
*
* \brief start exception handled code.
*
* This starts a block of exception handled code. This is done by
* creating a current exception environment.
*/
#define TRY \
{ \
excenv_new (EXC_INIT ()); \
if (setjmp (* excenv_jmp_buf (EXC_INIT ())) == 0)
/**
* \param ee will hold the exception environment actually handled.
* \pre a current exception environment must exists.
* \return Nothing
* \post ee holds the current exception environment and it is removed
* from the stack of exception environments.
*
* \brief start exception handling.
*
* This starts a block of exception handling. This is done by
* retrieving the actual exception environment into \a ee.
*/
#define CATCH(ee) \
ee = excenv_catch (EXC_INIT ()); \
} \
if (excenv_has_exception(ee) == 0) \
free_catched (ee); \
else
/**
* \param e the exception to be thrown.
* \pre a current exception environment must exist.
* \return Nothing
* \post \a e is put into the current exception environment.
*
* \brief Throws an exception into the actual exception environment.
*/
#define THROW(e) \
exc_throw (EXC_INIT (), (e))
/**
* \brief this is just a wrapper around exc_new().
*
* This is just a wrapper around exc_new() that fills in automatically
* file and line.
*/
#define EXC(lvl, errnum, err_msg) \
exc_new (lvl, __FILE__, __LINE__, errnum, err_msg)
/**
* \brief a wrapper for exc_in_this_try()
*/
#define EXC_IN_THIS_TRY(e) \
exc_in_this_try (e)
void * exc_init ();
void * threaded_exc_init ();
void excenv_new (void *);
jmp_buf * excenv_jmp_buf (void *);
void exc_throw (void *, const exception_t *);
excenv_t * excenv_catch (void *);
int excenv_has_exception (const excenv_t *);
exception_t * exc_new (
const enum exclvl_t,
const char *,
const int,
const int,
const char *);
exception_t * retrive_exception (const excenv_t *);
void free_catched (excenv_t *);
void free_exception (exception_t *);
void thread_exc_end (THREAD_T);
void exc_end (void);
void print_exception (exception_t *);
void print_all_exceptions (excenv_t *);
void forward_all_exceptions (excenv_t *);
int exc_in_this_try (exception_t *);
enum exclvl_t exc_lvl_get (exception_t *);
char * exc_file_get (exception_t *);
int exc_line_get (exception_t *);
int exc_errnum_get (exception_t *);
char * exc_err_msg_get (exception_t *);
#endif /* EXCEPTION_H */