Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 57962:c1972eef3579
Merged revisions 77088 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77088 | georg.brandl | 2009-12-28 09:34:58 +0100 (Mo, 28 Dez 2009) | 1 line
#7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
........
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 28 Dec 2009 08:41:01 +0000 |
| parents | 77cfef596d33 |
| children | 3357b8ebb259 |
comparison
equal
deleted
inserted
replaced
| 57960:ffd800ef46ea | 57962:c1972eef3579 |
|---|---|
| 691 Py_XDECREF(classname); | 691 Py_XDECREF(classname); |
| 692 Py_XDECREF(modulename); | 692 Py_XDECREF(modulename); |
| 693 return result; | 693 return result; |
| 694 } | 694 } |
| 695 | 695 |
| 696 | |
| 697 /* Create an exception with docstring */ | |
| 698 PyObject * | |
| 699 PyErr_NewExceptionWithDoc(const char *name, const char *doc, | |
| 700 PyObject *base, PyObject *dict) | |
| 701 { | |
| 702 int result; | |
| 703 PyObject *ret = NULL; | |
| 704 PyObject *mydict = NULL; /* points to the dict only if we create it */ | |
| 705 PyObject *docobj; | |
| 706 | |
| 707 if (dict == NULL) { | |
| 708 dict = mydict = PyDict_New(); | |
| 709 if (dict == NULL) { | |
| 710 return NULL; | |
| 711 } | |
| 712 } | |
| 713 | |
| 714 if (doc != NULL) { | |
| 715 docobj = PyUnicode_FromString(doc); | |
| 716 if (docobj == NULL) | |
| 717 goto failure; | |
| 718 result = PyDict_SetItemString(dict, "__doc__", docobj); | |
| 719 Py_DECREF(docobj); | |
| 720 if (result < 0) | |
| 721 goto failure; | |
| 722 } | |
| 723 | |
| 724 ret = PyErr_NewException(name, base, dict); | |
| 725 failure: | |
| 726 Py_XDECREF(mydict); | |
| 727 return ret; | |
| 728 } | |
| 729 | |
| 730 | |
| 696 /* Call when an exception has occurred but there is no way for Python | 731 /* Call when an exception has occurred but there is no way for Python |
| 697 to handle it. Examples: exception in __del__ or during GC. */ | 732 to handle it. Examples: exception in __del__ or during GC. */ |
| 698 void | 733 void |
| 699 PyErr_WriteUnraisable(PyObject *obj) | 734 PyErr_WriteUnraisable(PyObject *obj) |
| 700 { | 735 { |
