title: How to catch laravel controller exceptions
body: <p>I'm new to Laravel (we're using 5.0 at work). Right now, when we respond to an API request in a Controller, we are rewriting the same code over and over to respond to unauthorized actions. For example,</p>
  
  <pre><code>public function getUsers(){
    if (Entrust::can('users.view')){
      $users = Users::get();
      return response()-&gt;done($users, 200);
    } else {
      return response()-&gt;unauthorized('users.view');
    }
  }
  </code></pre>
  
  <p>It gets more and more complicated if we have different permissions that can allow an API request to succeed.</p>
  
  <p>I'd like to simply throw an exception of some sort if the user cannot perform the API request. For example,</p>
  
  <pre><code>public function getUsers(){
    require('users.view'); // throws an UnauthorizedException if current user doesn't have 'users.view' permission
  
    $users = User::get();
    return response()-&gt;done($users, 200);
  }
  
  public function someOtherMethod(){
    if (!Entrust::can('permission1') &amp;&amp; !Entrust::can('permission2')){
      throw new UnauthorizedException(['permission1', 'permission2']);
    }
  
    // some other stuff
  }
  </code></pre>
  
  <p>But I don't know what code calls the API function, nor where to wrap that call in a try/catch. It's easy enough to code the UnauthorizedException, and easy to transform it into json, but where do I put the handler? As I said, I'm new to Laravel, and I don't know how it handles these exceptions.</p>
  
  <p>Ideally, whatever solution I find, I'd like to extend it to other exceptions so we can have consistent json responses based on common exceptions.</p>