Trying to get property of non-object throws exception that cannot be handled In a custom Drupal 8 module I decided to wrap a line of code in a try...catch block, in case $node was null.

I understand that in php errors and exceptions are different, and according to Error message - Trying to get property of non-object this is an error, so will not be handled by try...catch, and the code should continue to run after the error. 

However when this code runs under Drupal 8 the error hander raises an exception. So I added the try...catch block. But the exception is still unhandled crashed the program. 

This is a cut-down version of my code:

$node = null;
try {
  // The next line results in an unhandled exception 
  $f = $node-&gt;field_example;
} catch (Exception $e) {
  // Never gets here
  watchdog_exception('example', $e);
}
// Never gets here


Am I missing something? Surely this can't be the intended behaviour?
I actually over-simplified by question. The crash doesn't happen in the simple case I posted, just an error and execution continues. It arises when I use field API syntax to refer to a null referenced entity, and only then when the target_id is not null.

$node-&gt;field_foo-&gt;target_id = 999; // term 999 does not exist
try {
  // The next line results in an unhandled exception 
  $v = $node-&gt;field_foo-&gt;entity-&gt;field_bar-&gt;value;
} catch (\Exception $e) {
  // Never gets here
  watchdog_exception('example', $e);
}
// And never gets to continue here


The issue was why and Drupal does this. The solution (thanks @Clive) is to replace catch (\Exception $e) with catch (\Throwable $e)