gambitproject / gambit

Gambit: The package for computation in game theory
http://www.gambit-project.org
GNU General Public License v2.0
400 stars 150 forks source link

BUG: Unhandled exceptions from C++ in `pygambit` #391

Closed tturocy closed 11 months ago

tturocy commented 11 months ago

Overview

In the Cython wrapper definitions file gambit.pxd, not all functions are declared with except +. This means that if any of these functions does raise an exception, the result is an unhandled C++ exception which in general terminates the Python interpreter.

We mostly guard against this at the Cython level, but at the moment this does lead to problems in the case of invalid mixed strategy and behavior profiles, as in #389.

To do

The most straightforward solution is to wrap everything with except +, which at least will convert all exceptions to a generic Python RuntimeError exception.

Before doing so it might be worth taking a few minutes to understand whether there are any costs to doing this, as there are a number of functions which really ought never to throw an exception unless something is horribly wrong.