$user = User::findOrFail($userId);
$user = User::where('email', $email)->firstOrFail();
use Illuminate\Database\Eloquent\ModelNotFoundException; //... try { $user = User::findOrFail($userId); } catch (ModelNotFoundException $e) { // Handle the exception }In this example, we are using a try-catch block to catch the `ModelNotFoundException` exception that is thrown if the user record is not found. We can then handle the exception in any way we like. The `findOrFail` method is part of the Laravel framework, which is a popular PHP web application framework. It is included in the `illuminate/database` package.