How to terminate a batch when an error occurs
To set $current_set['success'] to FALSE, you can use the following code.

$current_set = &amp;_batch_current_set();
$current_set['success'] = FALSE;


To set the messages to show to the users, you can use the following code.

$batch_context['results'][] = 'The error to be shown to the user';
$batch_context['finished'] = 1.0;


$batch_context is the last argument passed to the operation callback.

The "finished" callback receives $current_set['success'], and $batch_context['results'] respectively as first, and second argument. It can show the errors to the users using drupal_set_message().

References


_batch_process()
_batch_finished()