The C++ language interface for MPI includes the predefined error handler MPI::ERRORS_THROW_EXCEPTIONS for use with MPI::Comm::Set_errhandler, MPI::File::Set_errhandler, and MPI::Win::Set_errhandler. MPI::ERRORS_THROW_EXCEPTIONS can only be set or retrieved by C++ functions. If a non-C++ program causes an error that invokes the MPI::ERRORS_THROW_EXCEPTIONS error handler, the exception will pass up the calling stack until C++ code can catch it. If there is no C++ code to catch it, the behavior is undefined.
The error handler MPI::ERRORS_THROW_EXCEPTIONS causes an MPI::Exception to be thrown for any MPI result code other than MPI::SUCCESS.
The C++ bindings for exceptions follow:
namespace MPI [ Exception::Exception(int error_code); int Exception::Get_error_code() const; int Exception::Get_error_class() const; const char* Exception::Get_error_string() const; ];
The public interface to MPI::Exception class is defined as follows:
namespace MPI [
class Exception [
public:
Exception(int error_code);
int Get_error_code() const;
int Get_error_class() const;
const char *Get_error_string() const;
];
];
The PE MPI implementation follows:
public:
Exception(int ec) : error_code(ec)
[
(void)MPI_Error_class(error_code, &error_class);
int resultlen;
(void)MPI_Error_string(error_code, error_string, &resultlen);
]
virtual ~Exception(){ }
virtual int Get_error_code() const
[
return error_code;
]
virtual int Get_error_class() const
[
return error_class;
]
virtual const char* Get_error_string() const
[
return error_string;
]
protected:
int error_code;
char error_string[MPI_MAX_ERROR_STRING];
int error_class;
};