EntityTypeManager database transaction
You can create the node without saving it.  You wouldn't really need a try catch if you know what types of data you're saving.

    $node = \Drupal::EntityTypeManager()-&gt;getStorage('node')-&gt;create([
      'type' =&gt; 'news',
      'title' =&gt; "hello world",
      'field_some_textfield' =&gt; "Here's some text",
    ]);

    $node-&gt;set('status', 1);
    $node-&gt;set('field_site_section', [['target_id' =&gt; 6]]);
    $node-&gt;set('field_first_name', $data-&gt;firstName);
    if (!empty($data-&gt;middleName)) {
      $node-&gt;set('field_middle_name', $data-&gt;middleName);
    }
    $node-&gt;set('field_last_name', $data-&gt;lastName);


When you're satisfied that your node is set up properly, then you can call:

$node-&gt;save();


At this point, you can get the node id this way:

$nid = $node-&gt;id();