Using $_SESSION to Display Errors

if ( !session_id() ) {
    session_start();
}
if ($error) {
    $_SESSION['my_plugin_errors'] = $error->get_error_message();
}
if ( array_key_exists( 'my_plugin_errors', $_SESSION ) ) {?>