def testAddErrorClassCodeString(self): try: errclass = MPI.Add_error_class() except NotImplementedError: self.skipTest('mpi-add_error_class') lastused = MPI.COMM_WORLD.Get_attr(MPI.LASTUSEDCODE) self.assertTrue(errclass == lastused) errstr = MPI.Get_error_string(errclass) self.assertEqual(errstr, "") MPI.Add_error_string(errclass, "error class") self.assertEqual(MPI.Get_error_string(errclass), "error class") errcode1 = MPI.Add_error_code(errclass) errstr = MPI.Get_error_string(errcode1) self.assertEqual(errstr, "") MPI.Add_error_string(errcode1, "error code 1") self.assertEqual(MPI.Get_error_class(errcode1), errclass) self.assertEqual(MPI.Get_error_string(errcode1), "error code 1") errcode2 = MPI.Add_error_code(errclass) errstr = MPI.Get_error_string(errcode2) self.assertEqual(errstr, "") MPI.Add_error_string(errcode2, "error code 2") self.assertEqual(MPI.Get_error_class(errcode2), errclass) self.assertEqual(MPI.Get_error_string(errcode2), "error code 2")
# eh becomes MPI.ERRHANDLER_NULL after the Free operation assert eh == MPI.ERRHANDLER_NULL # recover the default errhandler obj.Set_errhandler(default_eh) # call error hander MPI.ERR_OTHER, which is known error not in list obj.Call_errhandler(MPI.ERR_OTHER) fh.Close() # error class, error code, error string # add a new error class errclass = MPI.Add_error_class() # add an error code to the new error class errcode = MPI.Add_error_code(errclass) # associate an error string with an the error errorcode MPI.Add_error_string(errcode, 'Example error string') print 'The new error class:', MPI.Get_error_class(errcode) print 'The new error string:', MPI.Get_error_string(errcode) # MPI.Exception # errexc = MPI.Exception(errclass) # create an MPI.Exception object from MPI.ERR_OTHER errexc = MPI.Exception(MPI.ERR_OTHER) print 'MPI.Exception is a subclass of RuntimeError:', isinstance( errexc, RuntimeError) print 'Error class of MPI.ERR_OTHER:', errexc.Get_error_class() print 'Error code of MPI.ERR_OTHER:', errexc.Get_error_code() print 'Error string of MPI.ERR_OTHER:', errexc.Get_error_string() # show exception catch try: