GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use BOOST_ASSERT instead of std::runtime_error to indicate errors. · arrowd/python@e80545a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test
    • exec.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/exec.cpp‎

Copy file name to clipboardExpand all lines: test/exec.cpp
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include <boost/python.hpp>
7+
#define BOOST_ENABLE_ASSERT_HANDLER 1
8+
#include <boost/assert.hpp>
79
#include <iostream>
810

11+
namespace boost
12+
{
13+
14+
void assertion_failed(char const * expr, char const * function,
15+
char const * file, long line)
16+
{
17+
std::cerr << "assertion failed : " << expr << " in " << function
18+
<< " at " << file << ':' << line << std::endl;
19+
abort();
20+
}
21+
22+
} // namespace boost
23+
924
namespace python = boost::python;
1025

1126
// An abstract base class
@@ -70,17 +85,15 @@ void exec_test()
7085

7186
// Creating and using instances of the C++ class is as easy as always.
7287
CppDerived cpp;
73-
if (cpp.hello() != "Hello from C++!")
74-
throw std::runtime_error("cpp.hello() returned unexpected string");
88+
BOOST_ASSERT(cpp.hello() == "Hello from C++!");
7589

7690
// But now creating and using instances of the Python class is almost
7791
// as easy!
7892
python::object py_base = PythonDerived();
7993
Base& py = python::extract<Base&>(py_base) BOOST_EXTRACT_WORKAROUND;
8094

8195
// Make sure the right 'hello' method is called.
82-
if (py.hello() != "Hello from Python!")
83-
throw std::runtime_error("py.hello() returned unexpected string");
96+
BOOST_ASSERT(py.hello() == "Hello from Python!");
8497
}
8598

8699
void exec_file_test(std::string const &script)
@@ -90,8 +103,7 @@ void exec_file_test(std::string const &script)
90103
python::object result = python::exec_file(script.c_str(), global, global);
91104

92105
// Extract an object the script stored in the global dictionary.
93-
if (python::extract<int>(global["number"]) != 42)
94-
throw std::runtime_error("'number' has unexpected value");
106+
BOOST_ASSERT(python::extract<int>(global["number"]) == 42);
95107
}
96108

97109
void exec_test_error()

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.