Handling a console save error

I am trying to save an entity in the console with a Command but if the save fails it gives a hard error.

if($articles->save($article)){
                $z++;
            }else{
                $var->error = '1';
            }

When I want to add a record but there is something wrong, like the database does not accept the field to be null. It returns a hard error and stops further execution. Is there a way to suppress the hard error? So the console command can finish processing.

Maybe have a try clause?

try {
  $articles->save($article));
  $z++;
} catch(\Exception $e) {
  $var->error = '1';
}