Boost logo

Boost Users :

From: cseymour_at_[hidden]
Date: 2002-08-19 18:21:33


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

This is a test
Raising an error
Aborted

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();
}

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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net