title: Exception handling problems in php
body: <p>I was trying out PHP exceptions for my project. But it turns out that the exception is thrown successfully but not being caught successfully by the code I wrote.</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code> try{
      require_once(MASTER_PHP."/master_validation.php");
      require_once(MASTER_PHP."/master_user.php");
      require_once(MASTER_PHP."/master_db.php");  require_once(MASTER_PHP."/master_secure.php");
      require_once(MASTER_PHP."/master_ui.php");
      require_once(MASTER_PHP."/master_mail.php");
      require_once(MASTER_PHP."/master_filehandling.php");
      require_once(MASTER_PHP."/master_archive.php");
      require_once(MASTER_PHP."/master_date.php");
      require_once(MASTER_PHP."/master_social.php");
      require_once(MASTER_PHP."/master_message.php");
      require_once(MASTER_PHP."/master_gallery.php");
      require_once(MASTER_PHP."/master_backup.php");
      require_once(MASTER_PHP."/master_payment.php");
      require_once(MASTER_PHP."/master_sms.php");
      require_once(MASTER_PHP."/master_xml.php");
  
      $filterobj=new ta_filtervalue();
      $filterobj-&gt;filterrequest();
  
      global $noecho;
      if($noecho!="yes")
      {
          $utilityobj=new ta_utilitymaster();
          $utilityobj-&gt;includeextassets();
      }
  }
  catch (Exception $e)
  {
      $custerrcode=$e-&gt;getMessage();
  $dbobj=new ta_dboperations();
  $res=$dbobj-&gt;dbquery("SELECT * FROM ".ERROR_CODES." WHERE ".errordb_errcode."='$custerrcode' LIMIT 0,1",DB_ERROR);
  
  $errmsg=$res[0][changesqlquote(errordb_errdesc,"")];
  $errpriority=$res[0][changesqlquote(errordb_errpriority,"")];
  $errcallback1=$res[0][changesqlquote(errordb_errcallback1,"")];
  $errcalltext1=$res[0][changesqlquote(errordb_errcallbacktext1,"")];
  $errcallback2=$res[0][changesqlquote(errordb_errcallback2,"")];
  $errcalltext2=$res[0][changesqlquote(errordb_errcallbacktext2,"")];
  $errtitle=$res[0][changesqlquote(errordb_errtitle,"")];
  
  $errobj=new ta_errorhandle();
  $errobj-&gt;senderror($errmsg,$custerrcode,$errpriority,$errcallback1,$errcalltext1,$errcallback2,$errcalltext2,$errtitle);
  }
  </code></pre>
  
  <p>If the exception occurs in <code>master_user.php</code> (required file) it has to be caught in the file which requires it. But it does not catch the exception.</p>
  
  <p>The way I throw the exception: </p>
  
  <pre><code>throw new Exception('#ta@0000000_0000000');
  </code></pre>
  
  <p>where the string inside is the error code.</p>
  
  <p>The error message: </p>
  
  <pre class="lang-none prettyprint-override"><code>Fatal error: Uncaught exception 'Exception' with message '#ta@0000000_0000000' in 
  C:\xampp\htdocs\techahoy\securedir\phpmaster\master_user.php:19 Stack trace: #0 
  C:\xampp\htdocs\techahoy\login\profile.php(4): ta_userinfo-&gt;userinit() #1 {main} thrown in
  C:\xampp\htdocs\techahoy\securedir\phpmaster\master_user.php on line 19
  </code></pre>