if function getValue() on null return nothing
You can check if a field is empty or not before asking for getValue() with:

if (!$entity-&gt;get('field_name')-&gt;isEmpty()) {
  $value = $entity-&gt;get('field_name')-&gt;getValue();
}