---
name: "modbus_reply_exception"
section: "3"
platform: "linux"
package: "libmodbus-dev"
version: "3.1.6-2.1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/modbus_reply_exception"
---

# modbus\_reply\_exception(3)

send an exception response

## NAME

modbus\_reply\_exception - send an exception response

## SYNOPSIS

\*int modbus\_reply\_exception(modbus\_t \**ctx*, const uint8\_t \**req*, unsigned int *exception\_code*);

## DESCRIPTION

The **modbus\_reply\_exception()** function shall send an exception response based on the *exception\_code* in argument.

The libmodbus provides the following exception codes:

• MODBUS\_EXCEPTION\_ILLEGAL\_FUNCTION (1)

• MODBUS\_EXCEPTION\_ILLEGAL\_DATA\_ADDRESS (2)

• MODBUS\_EXCEPTION\_ILLEGAL\_DATA\_VALUE (3)

• MODBUS\_EXCEPTION\_SLAVE\_OR\_SERVER\_FAILURE (4)

• MODBUS\_EXCEPTION\_ACKNOWLEDGE (5)

• MODBUS\_EXCEPTION\_SLAVE\_OR\_SERVER\_BUSY (6)

• MODBUS\_EXCEPTION\_NEGATIVE\_ACKNOWLEDGE (7)

• MODBUS\_EXCEPTION\_MEMORY\_PARITY (8)

• MODBUS\_EXCEPTION\_NOT\_DEFINED (9)

• MODBUS\_EXCEPTION\_GATEWAY\_PATH (10)

• MODBUS\_EXCEPTION\_GATEWAY\_TARGET (11)

The initial request *req* is required to build a valid response.

## RETURN VALUE

The function shall return the length of the response sent if successful. Otherwise it shall return -1 and set errno.

## ERRORS

**EINVAL**

The exception code is invalid

## SEE ALSO

[**modbus\_reply**(3)](/modbus_reply/3.md) [**libmodbus**(7)](/libmodbus/7.md)

## AUTHORS

The libmodbus documentation was written by Stéphane Raimbault \<stephane.raimbault@gmail.com\>
