Wrong exception handling in pybind11 io.cpp

Issue #1004 new
Michal Habera created an issue

There is a code like

try
{
} catch (std::exception& e)
{
  // Do nothing, pybind11 will try next function
}

in io.cpp. It assumes that next function binding is tried which is not true. Pybind11 would try to match another method if exception would be thrown. Such silent pass is undesirable, nothing happens and pybind11 is happy...

This issue together with problems in issue #1002 resulted in apparent seamless behaviour that is incorrect.

Comments (3)

  1. Michal Habera reporter

    I do not know If there are other silent exception catches like this in our bindings, @chris_richardson and @garth-wells be aware or correct me, please.

  2. Chris Richardson

    @michalhabera - I'm sure there are several shortcomings in the pybind11 bindings. If you can post a pull request with a patch (an preferably a test too) that would be great.

  3. Michal Habera reporter

    Just for completeness, I have found out it is possible to "try next function" if py::reference_cast_error is thrown. The code would look like

    try
    {
      // some error happens
    } catch (std::exception& e)
    {
      // try next binding or propagate the exception if this is the last choice
      throw py::reference_cast_error();
    }
    
  4. Log in to comment