How to check if entity id exists or valid? I have created a content entity type. When I save form, I got id in routing url, like:

entityform/1

entityform/2


But if I directly access some non-existing id like entityform/999, page dies.

In watchdog, it is showing error, 


  Error: Call to a member function get() on null in Drupal...


I can not call function get() on the fields of entity, if entity doesn't exists.

$content_type = $entity-&gt;get('ctype')-&gt;value;


How to apply this check, whether entity actually created or not?
You can check if the entity object isset() or is not NULL, and use get() only if the condition passes.