## 34.13. Notice Processing [](<>) Notice and warning messages generated by the server are not returned by the query execution functions, since they do not imply failure of the query. Instead they are passed to a notice handling function, and execution continues normally after the handler returns. The default notice handling function prints the message on`stderr`, but the application can override this behavior by supplying its own handling function. For historical reasons, there are two levels of notice handling, called the notice receiver and notice processor. The default behavior is for the notice receiver to format the notice and pass a string to the notice processor for printing. However, an application that chooses to provide its own notice receiver will typically ignore the notice processor layer and just do all the work in the notice receiver. The function`PQsetNoticeReceiver` [](<>) [](<>)sets or examines the current notice receiver for a connection object. Similarly,`PQsetNoticeProcessor` [](<>) [](<>)sets or examines the current notice processor. ``` typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res); PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg); typedef void (*PQnoticeProcessor) (void *arg, const char *message); PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg); ``` Each of these functions returns the previous notice receiver or processor function pointer, and sets the new value. If you supply a null function pointer, no action is taken, but the current pointer is returned. When a notice or warning message is received from the server, or generated internally by libpq, the notice receiver function is called. It is passed the message in the form of a`PGRES_NONFATAL_ERROR` `PGresult`. (This allows the receiver to extract individual fields using[`PQresultErrorField`](libpq-exec.html#LIBPQ-PQRESULTERRORFIELD), or obtain a complete preformatted message using[`PQresultErrorMessage`](libpq-exec.html#LIBPQ-PQRESULTERRORMESSAGE)or[`PQresultVerboseErrorMessage`](libpq-exec.html#LIBPQ-PQRESULTVERBOSEERRORMESSAGE).) The same void pointer passed to`PQsetNoticeReceiver`也通过了。(如果需要,此指针可用于访问特定于应用程序的状态。) 默认通知接收者只是简单地提取消息(使用[`PQresultErrorMessage`](libpq-exec.html#LIBPQ-PQRESULTERRORMESSAGE)) 并将其传递给通知处理器。 通知处理器负责处理以文本形式给出的通知或警告消息。它被传递消息的字符串文本(包括尾随换行符),加上一个与传递给相同的空指针`PQsetNoticeProcessor`.(如果需要,此指针可用于访问特定于应用程序的状态。) 默认通知处理器很简单: ``` static void defaultNoticeProcessor(void *arg, const char *message) { fprintf(stderr, "%s", message); } ``` 一旦您设置了通知接收器或处理器,您应该期望该函数可以被调用,只要`PGconn`对象或`PG结果`由它制成的物体存在。在创建一个`PG结果`, 这`PGconn`的当前通知处理指针被复制到`PG结果`供可能的功能使用,例如[`PQgetvalue`](libpq-exec.html#LIBPQ-PQGETVALUE).