This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author giacometti
Recipients
Date 2001-08-09.22:36:51
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=93657

A) Direct code replacement.
Here is a non-exhaustive list of occurences:

pythonrun.c-2.1:1242
	w = Py_BuildValue("(sO)", msg, v);
	Py_XDECREF(v);
	PyErr_SetObject(errtype, w);
	Py_XDECREF(w);
--> PyErr_Raise( errtype, "sO", msg, v); Py_XDECREF( v);

errors.c:towards 303 and 350:
	if (filename != NULL)
		v = Py_BuildValue("(iss)", err, s, filename);
	else
		v = Py_BuildValue("(is)", err, s);
	if (v != NULL) {
		PyErr_SetObject(PyExc_WindowsError, v);
		Py_DECREF(v);
--> if (filename) PyErr_Raise( Pyexc_WindowsError, "iss", err, s, filename) else PyErr_Raise( ..., "is", err, s);

compile.c: 421
	w = Py_BuildValue("(OO)", v, t);
	if (w == NULL)
		goto exit;
	PyErr_SetObject(exc, w);
--> PyErr_Raise( exc, "OO", v, t)

Modules/socketmodules.c:361
            v = Py_BuildValue("(is)", myerrorcode, outbuf);
            if (v != NULL) {
                PyErr_SetObject(PySocket_Error, v);
                Py_DECREF(v);
            }
            return NULL;
--> return PyErr_Raise( PySocketError, "is", myerrorcode, outbuf);

posixmodule.c:441
    v = Py_BuildValue("(is)", code, text);
    if (v != NULL) {
        PyErr_SetObject(PyExc_OSError, v);
        Py_DECREF(v);
    }
    return NULL; /* Signal to Python that an Exception is Pending */
--> return PyErr_Raise( PyExc_OSError, "is", code, text);

.....


B) Other use of PyErr_Raise* in the current code base:
----------------------------------------------

As of today, there are 3 functions for raising a new exception:
- PyErr_SetString (1118 occurences)
- PyErr_Format (158 occurences)
- PyErr_SetObject (48 occurences)

PyErr_Raise( exctype, "O", obj) would replace PyErr_SetObject( exctype, obj)
PyErr_Raise( exctype, "s", msg) would replace PyErr_SetString( exctype, msg)

PyErr_SetObject and PyErr_SetString could then both be deprecated, in cases the arg is not already an 
instance of the exception...
Here is some explaination:

Historically, Python was first working with string exceptions, only. Structured object-oriented exceptions 
were introduced only towards the 1.5 releases, I think (very approximately - I've only used python 1.5.1 or 
later...).

It is not also also how the current API works with exception whose __init__ require more than two args, 
and process them.
If you want to raise an exception with an __init__ that has to or more args, there is presently no clear way 
of doing it; this is where i created the PyErr_Raise* functions.
There is also the case where one would define an exception which does not accept a string object as 
__init__ argument... PyErr_SetString would create problem there too.

Furthermore, the exact semantics and workings of PyErr_Object are not clear, with regard to the type of 
the object passed (this is fine when the object is already an instance of the exception class, but when it is 
not an instance of the exception class, huum).
Use of PyErr_Raise would clarify this...


History
Date User Action Args
2007-08-23 15:06:54adminlinkissue448305 messages
2007-08-23 15:06:54admincreate