comparison Python/errors.c @ 1832:79e420805c67 legacy-trunk

err_clear: clear interpreter stack trace
author Guido van Rossum <guido@python.org>
date Mon, 29 Aug 1994 12:14:12 +0000
parents cd397266dc1c
children ada19aaaf8c0
comparison
equal deleted inserted replaced
1831:216b755515e6 1832:79e420805c67
1 /*********************************************************** 1 /***********************************************************
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, 2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands. 3 Amsterdam, The Netherlands.
4 4
5 All Rights Reserved 5 All Rights Reserved
6 6
7 Permission to use, copy, modify, and distribute this software and its 7 Permission to use, copy, modify, and distribute this software and its
58 #include "allobjects.h" 58 #include "allobjects.h"
59 #include "modsupport.h" 59 #include "modsupport.h"
60 60
61 #include <errno.h> 61 #include <errno.h>
62 62
63 #include "errcode.h"
64
65 extern char *strerror PROTO((int)); 63 extern char *strerror PROTO((int));
66 64
67 /* Last exception stored by err_setval() */ 65 /* Last exception stored by err_setval() */
68 66
69 static object *last_exception; 67 static object *last_exception;
98 object *value = newstringobject(string); 96 object *value = newstringobject(string);
99 err_setval(exception, value); 97 err_setval(exception, value);
100 XDECREF(value); 98 XDECREF(value);
101 } 99 }
102 100
103 int 101
102 object *
104 err_occurred() 103 err_occurred()
105 { 104 {
106 return last_exception != NULL; 105 return last_exception;
107 } 106 }
108 107
109 void 108 void
110 err_get(p_exc, p_val) 109 err_get(p_exc, p_val)
111 object **p_exc; 110 object **p_exc;
145 object * 144 object *
146 err_errno(exc) 145 err_errno(exc)
147 object *exc; 146 object *exc;
148 { 147 {
149 object *v; 148 object *v;
150 if (errno == EINTR && intrcheck()) { 149 int i = errno;
151 err_set(KeyboardInterrupt); 150 if (i == EINTR && sigcheck())
152 return NULL; 151 return NULL;
153 } 152 v = mkvalue("(is)", i, strerror(i));
154 v = mkvalue("(is)", errno, strerror(errno));
155 if (v != NULL) { 153 if (v != NULL) {
156 err_setval(exc, v); 154 err_setval(exc, v);
157 DECREF(v); 155 DECREF(v);
158 } 156 }
159 return NULL; 157 return NULL;
162 void 160 void
163 err_badcall() 161 err_badcall()
164 { 162 {
165 err_setstr(SystemError, "bad argument to internal function"); 163 err_setstr(SystemError, "bad argument to internal function");
166 } 164 }
167
168 /* Set the error appropriate to the given input error code (see errcode.h) */
169
170 void
171 err_input(err)
172 int err;
173 {
174 switch (err) {
175 case E_DONE:
176 case E_OK:
177 break;
178 case E_SYNTAX:
179 err_setstr(SyntaxError, "invalid syntax");
180 break;
181 case E_TOKEN:
182 err_setstr(SyntaxError, "invalid token");
183 break;
184 case E_INTR:
185 err_set(KeyboardInterrupt);
186 break;
187 case E_NOMEM:
188 err_nomem();
189 break;
190 case E_EOF:
191 err_setstr(SyntaxError, "unexpected EOF while parsing");
192 break;
193 default:
194 err_setstr(SystemError, "unknown parsing error");
195 break;
196 }
197 }