diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 3be7b8d23e..1742b36ed6 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -65,6 +65,8 @@ def test_species(self): self.assertEqual(name, self.phase.species_name(i)) self.assertEqual(i, self.phase.species_index(name)) self.assertEqual(i, self.phase.species_index(i)) + with self.assertRaisesRegex(ct.CanteraError, 'IndexError thrown by Phase::checkSpeciesIndex'): + self.phase.species(self.phase.n_species) def test_elements(self): self.assertEqual(self.phase.n_elements, 3) diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index b3293b8fcd..03ed524c50 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -990,6 +990,7 @@ shared_ptr Phase::species(const std::string& name) const shared_ptr Phase::species(size_t k) const { + checkSpeciesIndex(k); return m_species.at(m_speciesNames[k]); }