How to throw an exception when a user is not found in Laravel 5.2
<p>I am trying these code and I wanna throw an exception when user is not found. How can I do that?</p>

<p>Thank you so much.</p>

<p>When user not found I am getting this error;</p>

<p>NotFoundHttpException in Handler.php line 102:
No query results for model [App\User]</p>

<pre><code>public function showProfile($username)
{   
   return $user = User::where('username', $username)-&gt;firstOrFail();
}
</code></pre>