title: How do I throw a custom try-catch exception on CakePHP?
body: <p>I want to throw a custom exception which is the data validation exception in a controller of my CakePHP application. How do I create my own custom exception handler in Cakephp so that I can throw the exception and catch the exception?</p>
  
  <p>My code example:</p>
  
  <pre><code>function getUserDetails($userid){
  
      try{
           if(!$validUser){
                throw new Exception('Invalid User');
           }
  
           return $userDetailsData;  //returned from db
      }catch(Exception $e){
           echo 'Error:'.$e-&gt;getMessage();
          return;
      }
  
  }
  </code></pre>
  
  <p>is it possible to use here custom Exception class in cakephp so that only those exception can be thrown that what i do. Hope it clarifies question.
  thanks.</p>