You can do this by hand, but WP natively does it like this for settings errors:
add_settings_error()
to create message.- Then
set_transient('settings_errors', get_settings_errors(), 30);
settings_errors()
inadmin_notices
hook to display (will need to hook for non-settings screens).