Use new exceptions.

This commit is contained in:
Guido van Rossum 1991-12-10 14:00:03 +00:00
parent 97ff5308fe
commit 87e7ea72a6
8 changed files with 39 additions and 48 deletions

View File

@ -68,6 +68,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "stdwin.h"
#define StdwinError RuntimeError /* XXX Change this later */
/* Window and menu object types declared here because of forward references */
typedef struct {
@ -870,7 +872,7 @@ text_draw(self, args)
if (!getrectarg(args, a))
return NULL;
if (Drawing != NULL) {
err_setstr(RuntimeError, "already drawing");
err_setstr(StdwinError, "already drawing");
return NULL;
}
/* Clip to text area and ignore if area is empty */
@ -1029,8 +1031,7 @@ text_settext(self, args)
return NULL;
size = getstringsize(text);
if ((buf = NEW(char, size)) == NULL) {
err_set(MemoryError);
return NULL;
return err_nomem();
}
memcpy(buf, getstringvalue(text), size);
tesetbuf(self->t_text, buf, size); /* Becomes owner of buffer */
@ -1145,7 +1146,7 @@ newmenuobject(title)
break;
}
if (id >= MAXNMENU) {
err_setstr(MemoryError, "creating too many menus");
err_setstr(StdwinError, "creating too many menus");
return NULL;
}
menu = wmenucreate(id + IDOFFSET, getstringvalue(title));
@ -1374,7 +1375,7 @@ window_begindrawing(wp, args)
if (!getnoarg(args))
return NULL;
if (Drawing != NULL) {
err_setstr(RuntimeError, "already drawing");
err_setstr(StdwinError, "already drawing");
return NULL;
}
dp = NEWOBJ(drawingobject, &Drawingtype);
@ -1596,7 +1597,7 @@ window_setwincursor(self, args)
return NULL;
c = wfetchcursor(getstringvalue(str));
if (c == NULL) {
err_setstr(RuntimeError, "no such cursor");
err_setstr(StdwinError, "no such cursor");
return NULL;
}
wsetwincursor(self->w_win, c);
@ -1710,7 +1711,7 @@ stdwin_open(sw, args)
break;
}
if (tag >= MAXNWIN) {
err_setstr(MemoryError, "creating too many windows");
err_setstr(StdwinError, "creating too many windows");
return NULL;
}
wp = NEWOBJ(windowobject, &Windowtype);
@ -1766,7 +1767,7 @@ stdwin_get_poll_event(poll, args)
if (!getnoarg(args))
return NULL;
if (Drawing != NULL) {
err_setstr(RuntimeError, "cannot getevent() while drawing");
err_setstr(StdwinError, "cannot getevent() while drawing");
return NULL;
}
again:

View File

@ -95,7 +95,7 @@ newfileobject(name, mode)
#endif
f->f_fp = fopen(name, mode);
if (f->f_fp == NULL) {
err_errno(RuntimeError);
err_errno(IOError);
DECREF(f);
return NULL;
}
@ -166,7 +166,7 @@ file_close(f, args)
if (sts == EOF) {
if (errno == 0)
errno = EIO;
return err_errno(RuntimeError);
return err_errno(IOError);
}
if (sts != 0)
return newintobject((long)sts);
@ -198,7 +198,7 @@ file_seek(f, args)
if (fseek(f->f_fp, offset, (int)whence) != 0) {
if (errno == 0)
errno = EIO;
return err_errno(RuntimeError);
return err_errno(IOError);
}
INCREF(None);
return None;
@ -219,7 +219,7 @@ file_tell(f, args)
if (offset == -1L) {
if (errno == 0)
errno = EIO;
return err_errno(RuntimeError);
return err_errno(IOError);
}
return newintobject(offset);
}
@ -237,7 +237,7 @@ file_flush(f, args)
if (fflush(f->f_fp) != 0) {
if (errno == 0)
errno = EIO;
return err_errno(RuntimeError);
return err_errno(IOError);
}
INCREF(None);
return None;
@ -441,7 +441,6 @@ file_write(f, args)
object *args;
{
int n, n2;
char *s;
if (f->f_fp == NULL) {
err_badarg();
return NULL;
@ -452,20 +451,11 @@ file_write(f, args)
}
f->f_softspace = 0;
errno = 0;
n = getstringsize(args);
s = getstringvalue(args);
if (n > BUFSIZ) {
fflush(f->f_fp);
n2 = write(fileno(f->f_fp), s, n);
fflush(f->f_fp);
}
else {
n2 = fwrite(s, 1, n, f->f_fp);
}
n2 = fwrite(getstringvalue(args), 1, n = getstringsize(args), f->f_fp);
if (n2 != n) {
if (errno == 0)
errno = EIO;
err_errno(RuntimeError);
err_errno(IOError);
return NULL;
}
INCREF(None);

View File

@ -543,7 +543,7 @@ listindex(self, args)
if (cmpobject(self->ob_item[i], args) == 0)
return newintobject(i);
}
err_setstr(RuntimeError, "list.index(x): x not in list");
err_setstr(ValueError, "list.index(x): x not in list");
return NULL;
}
@ -586,7 +586,7 @@ listremove(self, args)
}
}
err_setstr(RuntimeError, "list.remove(x): x not in list");
err_setstr(ValueError, "list.remove(x): x not in list");
return NULL;
}

View File

@ -168,7 +168,7 @@ getlongvalue(vv)
prev = x;
x = (x << SHIFT) + v->ob_digit[i];
if ((x >> SHIFT) != prev) {
err_setstr(RuntimeError,
err_setstr(ValueError,
"long int too long to convert");
return -1;
}
@ -422,7 +422,7 @@ long_divrem(a, b, prem)
if (size_b == 0) {
if (prem != NULL)
*prem = NULL;
err_setstr(RuntimeError, "long division by zero");
err_setstr(ZeroDivisionError, "long division or remainder");
return NULL;
}
if (size_a < size_b ||
@ -938,7 +938,7 @@ long_pow(a, w)
if (size_b == ~0)
size_b = 0;
else if (size_b < 0) {
err_setstr(RuntimeError, "long integer to the negative power");
err_setstr(ValueError, "long integer to the negative power");
return NULL;
}
@ -1054,11 +1054,11 @@ long_rshift(a, b)
if (shiftby == -1L && err_occurred())
return NULL;
if (shiftby < 0) {
err_setstr(RuntimeError, "negative shift count");
err_setstr(ValueError, "negative shift count");
return NULL;
}
if (shiftby > MASK) {
err_setstr(RuntimeError, "outrageous shift count");
err_setstr(ValueError, "outrageous shift count");
return NULL;
}
wordshift = shiftby / SHIFT;
@ -1105,11 +1105,11 @@ long_lshift(a, b)
if (shiftby == -1L && err_occurred())
return NULL;
if (shiftby < 0) {
err_setstr(RuntimeError, "negative shift count");
err_setstr(ValueError, "negative shift count");
return NULL;
}
if (shiftby > MASK) {
err_setstr(RuntimeError, "outrageous shift count");
err_setstr(ValueError, "outrageous shift count");
return NULL;
}
if (shiftby % SHIFT == 0) {

View File

@ -118,7 +118,7 @@ module_getattr(m, name)
}
res = dictlookup(m->md_dict, name);
if (res == NULL)
err_setstr(NameError, name);
err_setstr(AttributeError, name);
else
INCREF(res);
return res;
@ -131,7 +131,7 @@ module_setattr(m, name, v)
object *v;
{
if (strcmp(name, "__dict__") == 0 || strcmp(name, "__name__") == 0) {
err_setstr(NameError, "can't assign to reserved member name");
err_setstr(TypeError, "can't assign to reserved member name");
return -1;
}
if (v == NULL)

View File

@ -180,10 +180,10 @@ err_input(err)
case E_OK:
break;
case E_SYNTAX:
err_setstr(RuntimeError, "syntax error");
err_setstr(ValueError, "syntax error");
break;
case E_TOKEN:
err_setstr(RuntimeError, "illegal token");
err_setstr(ValueError, "illegal token");
break;
case E_INTR:
err_set(KeyboardInterrupt);
@ -195,7 +195,7 @@ err_input(err)
err_set(EOFError);
break;
default:
err_setstr(RuntimeError, "unknown input error");
err_setstr(SystemError, "unknown input error");
break;
}
}

View File

@ -191,7 +191,7 @@ rd_object(fp)
switch (type) {
case EOF:
err_setstr(RuntimeError, "EOF read where object expected");
err_setstr(EOFError, "EOF read where object expected");
return NULL;
case TYPE_NULL:
@ -227,7 +227,7 @@ rd_object(fp)
char *end;
n = rd_byte(fp);
if (fread(buf, 1, (int)n, fp) != n) {
err_setstr(RuntimeError,
err_setstr(EOFError,
"EOF read where object expected");
return NULL;
}
@ -235,11 +235,11 @@ rd_object(fp)
errno = 0;
res = strtod(buf, &end);
if (*end != '\0') {
err_setstr(RuntimeError, "bad float syntax");
err_setstr(ValueError, "bad float syntax");
return NULL;
}
if (errno != 0) {
err_setstr(RuntimeError,
err_setstr(ValueError,
"float constant too large");
return NULL;
}
@ -253,7 +253,7 @@ rd_object(fp)
if (fread(getstringvalue(v), 1, (int)n, fp) != n) {
DECREF(v);
v = NULL;
err_setstr(RuntimeError,
err_setstr(EOFError,
"EOF read where object expected");
}
}
@ -314,7 +314,7 @@ rd_object(fp)
return v;
default:
err_setstr(RuntimeError, "read unknown object");
err_setstr(TypeError, "read unknown object");
return NULL;
}

View File

@ -103,7 +103,7 @@ getmember(addr, mlist, name)
}
}
err_setstr(NameError, name);
err_setstr(AttributeError, name);
return NULL;
}
@ -119,7 +119,7 @@ setmember(addr, mlist, name, v)
for (l = mlist; l->name != NULL; l++) {
if (strcmp(l->name, name) == 0) {
if (l->readonly || l->type == T_STRING) {
err_setstr(RuntimeError, "readonly attribute");
err_setstr(TypeError, "readonly attribute");
return -1;
}
addr += l->offset;
@ -178,6 +178,6 @@ setmember(addr, mlist, name, v)
}
}
err_setstr(NameError, name);
err_setstr(AttributeError, name);
return -1;
}