Models and controllers SHOULD NOT terminate a script with an exit. Use an exception instead, so the application using the model or controller may respond to the failure. If the exception is not caught, it will result in a “Fatal error: Uncaught exception.”

Incorrect:

if (!file_exists($file)) {
    exit('Could not load file: ' . $file);
}


Correct:

if (!file_exists($file)) {
    throw new \Exception('Could not load file: ' . $file);
}


In many cases it is RECOMMENDED to throw a more specific Standard PHP Library (SPL) exception, for example a runtime exception if a file only exists after it was saved by an application.

Correct:

if (!file_exists($file)) {
    throw new \RuntimeException('Could not load file: ' . $file);
}