MySQL Internals Manual  /  Error Messages  /  Adding Storage Engine Error Messages

27.3 Adding Storage Engine Error Messages

To add error messages for table handlers, the following example may be helpful.

Purpose: Implement the handler::get_error_message function as ha_federated::get_error_message to return the handler-specific error message.


  1. When an error occurs you return an error code. (It should not be in the range of those that HA_ERR uses, which currently is 120-159.)

  2. When handler::print_error is called to convert the handler error code to a MySQL error code, it will enter the default label of the switch(error) statement:
      /* The error was "unknown" to this function.
     Ask handler if it has got a message for this error */
      bool temporary= FALSE;
      String str;
      temporary= get_error_message(error, &str);
      if (!str.is_empty())
    const char* engine= table_type();
    if (temporary)
      my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine);
      my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine);
  1. Thus the handler::get_error_message is called and you can return the handler-specific error message, which is either a static error message that you retrieve from an error/string array, or a dynamic one that you format when the error occurs.

When you have returned the error message it will be passed to MySQL and formatted as Got error %d '%-.100s' from %s. For example:

Got error 788 'Could not connect to remote server' from FEDERATED

The Got error %d part will be returned in the user's selected language, but the handler-specific one will use English (unless the handler supports returning the handler error message in the user's selected language).

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.