Checking return with WP Error

Not entirely sure what you are asking, but if I understand correctly you want to perform some testing on the return value in order to avoid iterating a WP_Error object and perhaps handle errors in some way.

According to the documentation get_terms() will return an array of term objects or false if no objects were found, but clearly by looking at the source it will return a WP_Error object if the taxonomy does not exists or in some cases an empty array.

Thus, to check for errors you will have to check if the return value matches false, empty array (array()) or a WP_Error object. Calling empty($terms) will account for the first two, and is_wp_error($terms) can be used for testing if the return value is an error object. Something like this will work for performing such testing:

$taxonomyName = "hhie_artists";
//Call top layer terms only (by setting Parent to 0).
$parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => true));   

if (!empty($parent_terms) && !is_wp_error($parent_terms)) {
    echo '<ul>';
    foreach ($parent_terms as $pterm) {
        //Get the Child terms
        $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => true));
        if (!empty($terms) && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';  
            }
        }
    }
    echo '</ul>';
}

However, there is already a function available in WordPress for printing a category tree like this. It’s called wp_list_categories and i strongly suggest you use that instead. Here’s how:

wp_list_categories(array(
    'title_li' => null, // We don't need the automatically generated heading
    'depth' => 1, // Judging from your code you only want to print one level of terms
    'orderby' => 'slug',
    'taxonomy' => 'hhie_artists',
));

The result should follow this structure:

  • Parent artist A
    • Child artist A1
    • Child artist A2
    • Child artist A3
  • Parent artist B
    • Child artist B1
    • Child artist B2