NEURON
err.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3 **
4 ** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
5 **
6 ** Meschach Library
7 **
8 ** This Meschach Library is provided "as is" without any express
9 ** or implied warranty of any kind with respect to this software.
10 ** In particular the authors shall not be liable for any direct,
11 ** indirect, special, incidental or consequential damages arising
12 ** in any way from use of the software.
13 **
14 ** Everyone is granted permission to copy, modify and redistribute this
15 ** Meschach Library, provided:
16 ** 1. All copies contain this copyright notice.
17 ** 2. All modified copies shall carry a notice stating who
18 ** made the last modification and the date of such modification.
19 ** 3. No charge is made for this software or works derived from it.
20 ** This clause shall not be construed as constraining other software
21 ** distributed on the same medium as this software, nor is a
22 ** distribution fee considered a charge.
23 **
24 ***************************************************************************/
25 
26 
27 /* err.h 28/09/1993 */
28 
29 /* RCS id: err.h,v 1.1 1997/11/03 16:15:48 hines Exp */
30 
31 
32 #ifndef ERRHEADER
33 #define ERRHEADER
34 
35 
36 #include <setjmp.h>
37 #include "machine.h"
38 
39 /* Error recovery */
40 
41 extern jmp_buf restart;
42 
43 
44 /* max. # of error lists */
45 #define ERR_LIST_MAX_LEN 10
46 
47 /* main error functions */
48 #ifndef ANSI_C
49 extern int ev_err(); /* main error handler */
50 extern int set_err_flag(); /* for different ways of handling
51  errors, returns old value */
52 extern int count_errs(); /* to avoid "too many errors" */
53 extern int err_list_attach(); /* for attaching a list of errors */
54 extern int err_is_list_attached(); /* checking if a list is attached */
55 extern int err_list_free(); /* freeing a list of errors */
56 
57 #else /* ANSI_C */
58 
59 extern int ev_err(char *,int,int,char *,int); /* main error handler */
60 extern int set_err_flag(int flag); /* for different ways of handling
61  errors, returns old value */
62 extern int count_errs(int true_false); /* to avoid "too many errors" */
63 extern int err_list_attach(int list_num, int list_len,
64  char **err_ptr,int warn); /* for attaching a list of errors */
65 extern int err_is_list_attached(int list_num); /* checking if a list
66  is attached */
67 extern int err_list_free(int list_num); /* freeing a list of errors */
68 
69 #endif
70 
71 
72 /* error(E_TYPE,"myfunc") raises error type E_TYPE for function my_func() */
73 #define error(err_num,fn_name) ev_err(__FILE__,err_num,__LINE__,fn_name,0)
74 
75 /* warning(WARN_TYPE,"myfunc") raises warning type WARN_TYPE for
76  function my_func() */
77 #define warning(err_num,fn_name) ev_err(__FILE__,err_num,__LINE__,fn_name,1)
78 
79 
80 /* error flags */
81 #define EF_EXIT 0 /* exit on error */
82 #define EF_ABORT 1 /* abort (dump core) on error */
83 #define EF_JUMP 2 /* jump on error */
84 #define EF_SILENT 3 /* jump, but don't print message */
85 #define ERREXIT() set_err_flag(EF_EXIT)
86 #define ERRABORT() set_err_flag(EF_ABORT)
87 /* don't print message */
88 #define SILENTERR() if ( ! setjmp(restart) ) set_err_flag(EF_SILENT)
89 /* return here on error */
90 #define ON_ERROR() if ( ! setjmp(restart) ) set_err_flag(EF_JUMP)
91 
92 
93 /* error types */
94 #define E_UNKNOWN 0
95 #define E_SIZES 1
96 #define E_BOUNDS 2
97 #define E_MEM 3
98 #define E_SING 4
99 #define E_POSDEF 5
100 #define E_FORMAT 6
101 #define E_INPUT 7
102 #define E_NULL 8
103 #define E_SQUARE 9
104 #define E_RANGE 10
105 #define E_INSITU2 11
106 #define E_INSITU 12
107 #define E_ITER 13
108 #define E_CONV 14
109 #define E_START 15
110 #define E_SIGNAL 16
111 #define E_INTERN 17
112 #define E_EOF 18
113 #define E_SHARED_VECS 19
114 #define E_NEG 20
115 #define E_OVERWRITE 21
116 #define E_BREAKDOWN 22
117 
118 /* warning types */
119 #define WARN_UNKNOWN 0
120 #define WARN_WRONG_TYPE 1
121 #define WARN_NO_MARK 2
122 #define WARN_RES_LESS_0 3
123 #define WARN_SHARED_VEC 4
124 
125 
126 /* error catching macros */
127 
128 /* execute err_part if error errnum is raised while executing ok_part */
129 #define catch(errnum,ok_part,err_part) \
130  { jmp_buf _save; int _err_num, _old_flag; \
131  _old_flag = set_err_flag(EF_SILENT); \
132  MEM_COPY(restart,_save,sizeof(jmp_buf)); \
133  if ( (_err_num=setjmp(restart)) == 0 ) \
134  { ok_part; \
135  set_err_flag(_old_flag); \
136  MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
137  else if ( _err_num == errnum ) \
138  { set_err_flag(_old_flag); \
139  MEM_COPY(_save,restart,sizeof(jmp_buf)); \
140  err_part; } \
141  else { set_err_flag(_old_flag); \
142  MEM_COPY(_save,restart,sizeof(jmp_buf)); \
143  error(_err_num,"catch"); \
144  } \
145  }
146 
147 
148 /* execute err_part if any error raised while executing ok_part */
149 #define catchall(ok_part,err_part) \
150  { jmp_buf _save; int _err_num, _old_flag; \
151  _old_flag = set_err_flag(EF_SILENT); \
152  MEM_COPY(restart,_save,sizeof(jmp_buf)); \
153  if ( (_err_num=setjmp(restart)) == 0 ) \
154  { ok_part; \
155  set_err_flag(_old_flag); \
156  MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
157  else \
158  { set_err_flag(_old_flag); \
159  MEM_COPY(_save,restart,sizeof(jmp_buf)); \
160  err_part; } \
161  }
162 
163 
164 /* print message if error raised while executing ok_part,
165  then re-raise error to trace calls */
166 #define tracecatch(ok_part,function) \
167  { jmp_buf _save; int _err_num, _old_flag; \
168  _old_flag = set_err_flag(EF_JUMP); \
169  MEM_COPY(restart,_save,sizeof(jmp_buf)); \
170  if ( (_err_num=setjmp(restart)) == 0 ) \
171  { ok_part; \
172  set_err_flag(_old_flag); \
173  MEM_COPY(_save,restart,sizeof(jmp_buf)); } \
174  else \
175  { set_err_flag(_old_flag); \
176  MEM_COPY(_save,restart,sizeof(jmp_buf)); \
177  error(_err_num,function); } \
178  }
179 
180 
181 
182 #endif /* ERRHEADER */
183 
int err_is_list_attached(int list_num)
Definition: err.c:188
int ev_err(char *, int, int, char *, int)
Definition: err.c:231
jmp_buf restart
Definition: err.c:110
int set_err_flag(int flag)
Definition: err.c:205
int err_list_attach(int list_num, int list_len, char **err_ptr, int warn)
Definition: err.c:138
int err_list_free(int list_num)
Definition: err.c:171
int count_errs(int true_false)
Definition: err.c:216