Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:31:26+00:00 2026-06-01T18:31:26+00:00

Is it safe to call PyErr_Set* to override an exception? According to the docs,

  • 0

Is it safe to call PyErr_Set* to override an exception? According to the docs, PySequence_Fast raises a TypeError with the const char * message argument supplied to it if there’s an error. Would it be safe to call PyErr_SetObject after PySequence_Fast raises an error?

Example:

static PyObject * myfunc(PyObject * self, PyObject * args) {
    PyObject * pyobj;
    PyObject * pyseq;
    PyObject * message;

    if (!PyArg_ParseTuple(args, "O", &pyobj)) {
        return NULL;
    }

    pyseq = PySequence_Fast(pyobj, "");
    if (pyseq == NULL) {
        message = PyString_FromFormat("argument is a '%s', not a sequence.", pyobj->ob_type->tp_name);
        PyErr_SetObject(PyExc_TypeError, message);
        Py_XDECREF(message);
        return NULL;
    }

    // ...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:31:28+00:00Added an answer on June 1, 2026 at 6:31 pm

    According to “Python/errors.c” from the Python 2.7.2 source code, PyErr_SetObject() calls PyErr_Restore() which Py_XDECREF()s any old exception state variables before setting the new ones. So yes, it is safe to override an existing exception. Just be aware that you are completely overriding the previous exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a TCP blocking socket, is it safe to call: if(SOCKET_ERROR != recv(s, NULL,
Is it safe if I want to call closesocket() on a server socket from
Is it safe to call SubmitChanges() when you are not sure whether the data
Is it safe to call the dispose() method of a JFrame from a different
Is it safe to call close on a form and then call close again
Possible Duplicate: Virtual member call in a constructor In C#, is it safe to
I cannot find any official documentation saying that it is safe to call Component.repaint
Ignoring programming style and design, is it safe to call delete on a variable
Is the standard Java 1.6 javax.xml.parsers.DocumentBuilder class thread safe? Is it safe to call
Is it safe to call RPy functions in a multiprocessing environment and are there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.