The get diagnostics statement retrieves error, warning, and informational messages from Client-Library. It is similar to, but more powerful than, the whenever statement, because you can expand it to retrieve more details of the detected errors.
If, within a whenever statement, you specify the application to go to or call another routine, specify get diagnostics in the function code, as follows:
void
error_handler()
{
exec sql begin declare section;
int num_msgs;
int condcnt;
exec sql include sqlca;
exec sql end declare section;
exec sql get diagnostics :num_msgs = number;
for (condcnt=1; condcnt <= num_msgs; condcnt++)
{
exec sql get diagnostics exception :condcnt
:sqlca = sqlca_info;
printf(“sqlcode is :%d\n\ message text:
%s\n”, sqlca.sqlcode,
sqlca.sqlerrm.sqlerrmc);
}
}