summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-12-10 13:52:31 (GMT)
committerGuido van Rossum <guido@python.org>1991-12-10 13:52:31 (GMT)
commit50afb7a2167c2f8c51b2453df0cdf692c1682723 (patch)
tree716e4a1b7639a04abee11d5f5cf8d3164faf9243 /Python/bltinmodule.c
parent68fc349744a48c18e278a4827a6f1782acb679a7 (diff)
downloadcpython-50afb7a2167c2f8c51b2453df0cdf692c1682723.zip
cpython-50afb7a2167c2f8c51b2453df0cdf692c1682723.tar.gz
cpython-50afb7a2167c2f8c51b2453df0cdf692c1682723.tar.bz2
Added new exceptions.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 3751ec3..25e8f42 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -66,7 +66,7 @@ builtin_chr(self, v)
}
x = getintvalue(v);
if (x < 0 || x >= 256) {
- err_setstr(RuntimeError, "chr() arg not in range(256)");
+ err_setstr(ValueError, "chr() arg not in range(256)");
return NULL;
}
s[0] = x;
@@ -335,7 +335,7 @@ min_max(v, sign)
}
n = (*sq->sq_length)(v);
if (n == 0) {
- err_setstr(RuntimeError, "min() or max() of empty sequence");
+ err_setstr(ValueError, "min() or max() of empty sequence");
return NULL;
}
w = (*sq->sq_item)(v, 0); /* Implies INCREF */
@@ -417,7 +417,7 @@ builtin_ord(self, v)
return NULL;
}
if (getstringsize(v) != 1) {
- err_setstr(RuntimeError, "ord() arg must have length 1");
+ err_setstr(ValueError, "ord() arg must have length 1");
return NULL;
}
return newintobject((long)(getstringvalue(v)[0] & 0xff));
@@ -488,7 +488,7 @@ builtin_range(self, v)
ilow = 0;
}
if (istep == 0) {
- err_setstr(RuntimeError, "zero step for range()");
+ err_setstr(ValueError, "zero step for range()");
return NULL;
}
/* XXX ought to check overflow of subtraction */
@@ -594,6 +594,15 @@ object *NameError;
object *SystemError;
object *KeyboardInterrupt;
+/* New exceptions */
+object *AttributeError;
+object *IOError;
+object *ZeroDivisionError;
+object *IndexError;
+object *ValueError;
+object *KeyError;
+object *OverflowError;
+
static object *
newstdexception(name, message)
char *name, *message;
@@ -615,6 +624,18 @@ initerrors()
SystemError = newstdexception("SystemError", "system error");
KeyboardInterrupt =
newstdexception("KeyboardInterrupt", "keyboard interrupt");
+
+ /* New exceptions */
+ AttributeError =
+ newstdexception("AttributeError", "undefined attribute");
+ IOError = newstdexception("IOError", "I/O error");
+ ZeroDivisionError =
+ newstdexception("ZeroDivisionError", "division by zero");
+ IndexError = newstdexception("IndexError", "index out of range");
+ ValueError = newstdexception("ValueError", "unacceptable value");
+ KeyError = newstdexception("KeyError", "invalid key");
+ OverflowError =
+ newstdexception("OverflowError", "arithmetic overflow");
}
void