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.)

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:

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 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:

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).