How to hide wordpress error message?

Depends on what you mean by “redirect”.

If you want to 404 them, this will do the job:

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    global $wp;
    $wp->handle_404();
    load_template(get_404_template());
    die();
}

If you actually want to redirect them somewhere, then you could do something like this, but that’s not exactly a “404”, as such.

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    wp_safe_redirect( get_home_url() );
    die();
}