title: How can I return json data when Laravel 5 catch exception?
body: <p>How can I return json data when laravel catch exception?
  I'd like to return Json data when the data does not exist on database. </p>
  
  <p>When laravel found the record from database, it returns correct json data.Yeah!
  If laravel have fail to search any record, it doesn't give json data!
  laravel just redireted the page which shows "Whoops, looks like something went wrong." and give soem extra information, "ModelNotFoundException".</p>
  
  <p>Following code is what I tried.</p>
  
  <pre><code>    public function show($id)
      {
              try {
                      $statusCode = 200;
                      $response = [
                              'todo' =&gt; []
                      ];
  
                      $todo = Todo::findOrFail($id);
  
                      $response['todo']= [
                              'id'       =&gt;       $todo-&gt;id,
                              'title'    =&gt;       $todo-&gt;title,
                              'body'     =&gt;       $todo-&gt;body,
                      ]; 
  
              } catch(Exception $e) {
                      // I think laravel doesn't go through following exception
                      $statusCode = 404;   
                      $response = [
                              "error" =&gt; "You do not have that record"
                      ];
  
              } finally {
                      return response($response, $statusCode);
  
              }
     }
  </code></pre>