Python 2.2.1 C API, extension modules, Boost

cseymour at cseymour at
Tue Aug 20 01:22:24 CEST 2002

Here is a sample program which shows the problem i've been having 
(posted in an earlier message). When I import the module "sample" and 
run the function test(), I get the following output:

This is a test
Raising an error

When I should get a message saying it caught the error, and then a 
Python error, instead of it Aborting and quitting Python.

/* sample.c */

#include "Python.h"
#include "boost/python/class_builder.hpp"

namespace py = boost::python;

void test()
  std::cout << "This is a test" << std::endl;
  std::cout << "Raising an error" << std::endl;

  PyErr_SetString(PyExc_TypeError, "This is the error");
  throw py::argument_error();

  try {
    py::module_builder this_module("sample");
    this_module.def(test, "test");
  catch (...) {
    std::cout << "Caught an error" << std::endl;

More information about the Python-list mailing list