---
title: ReportUserDefinedErrMsg
description: "用于开发者上报自定义错误码，推荐使用U码段，比如EU0001。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/runtimeapi/cann_base_api_0006.html
sourcePath: /source/zh/canncommercial/900/API/runtimeapi/cann_base_api_0006.html
indexId: c7356cee3f79547060b9fbf5ebb84ed832a13e6eec55906d4e1087fad9c78da068
---
# ReportUserDefinedErrMsg

#### 函数功能

用于开发者上报自定义错误码，推荐使用U码段，比如EU0001。

推荐是6位字符形式，对于像空格、非6位字符、以8888或9999结尾等不推荐的形式，函数内部会以错误码EU0000进行上报。

当使用该接口时，如果用户提供的格式化字符串长度超过1024（包括末尾的\0），接口将返回错误码-1，表示失败。例如，如果格式化字符串为“Error:%s”，且传入的字符串长度为1000，加上"Error:"和末尾的"\0"，总长度为1007，接口调用成功。然而，如果传入的字符串长度为1020，加上"Error:"和末尾的"\0"，总长度变为1027，超过1024，接口调用失败。


#### 函数原型

```
int32_t ReportUserDefinedErrMsg(const char *error_code, const char *format, …)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| error\_code | 输入 | 用户自定义的错误码。 |
| format | 输入 | 错误码对应的错误信息。 |
| ... | 输入 | format中的可变参数，表示format中占位符对应的变量值。 |


#### 返回值

- 0：成功。
- -1：失败。
