---
title: 异常处理程序
description: "- 注册用户例程函数以用作MPI异常处理程序。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0031.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/userg_hyperio_0031.html
indexId: c0c0be50b833c99413f8525eb93165d94f3181ec8db3a9538daf9622c8f3194358
---
# 异常处理程序

#### 函数定义

- 注册用户例程函数以用作MPI异常处理程序。
  MPI_File_create_errhandler(MPI_File_errhandler_function *function, MPI_Errhandler *errhandler)

  PMPI_File_create_errhandler(MPI_File_errhandler_function *function, MPI_Errhandler *errhandler)

- 提供错误码并调用异常处理程序。
  MPI_File_call_errhandler(MPI_File fh, int errorcode)

  PMPI_File_call_errhandler(MPI_File fh, int errorcode)

- 设置文件的异常处理程序。
  MPI_File_set_errhandler(MPI_File fh, MPI_Errhandler errhandler)

  PMPI_File_set_errhandler(MPI_File fh, MPI_Errhandler errhandler)

- 获取文件的异常处理程序。
  MPI_File_get_errhandler(MPI_File fh, MPI_Errhandler *errhandler)

  PMPI_File_get_errhandler(MPI_File fh, MPI_Errhandler *errhandler)


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| \*function | 用户定义异常处理程序 | 非空 | 输入 |
| \*errhandler | 目标地址，存放MPI错误处理（句柄） | 非空 | 输出 |
| fh | 绑定错误处理句柄的文件（句柄） | 非空 | 输入 |
| errorcode | MPI错误码 | 非空 | 输入 |
| errhandler | MPI错误处理（句柄） | 非空 | 输入 |


#### 返回值

- 成功：返回MPI_SUCCESS。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| MPI\_ERR\_FILE | 无效文件句柄 |
| MPI\_ERR\_ARG | 其他类型的无效参数 |
| MPI\_ERR\_OTHER | 其他错误 |


#### 注意

用户定义的异常处理程序正确性由用户进行保证。
