Drupal 8: The proper alternative to exit(); for terminating a request
You would have been looking for drupal_exit() in the past, but this was removed in D8. It is now advised to use the appropriate HTTP Exception. See the example on the change notice:

https://www.drupal.org/node/2017339