Define and use your own exception class : Your own Exceptions : Development PHP Source Code


PHP Source Code » Development » Your own Exceptions »

 

Define and use your own exception class



<?php

   class MyException extends Exception {
   
      function __construct($language,$errorcode) {
         $this->language = $language;
         $this->errorcode = $errorcode;
      }

      function getMessageMap() {
         $errors = file("text.txt");
         foreach($errors as $error) {
            list($key,$value= explode(",",$error,2);
            $errorArray[$key= $value;
         }
         return $errorArray[$this->errorcode];
      }
   }

   try {
      throw new MyException("english",4);
   }
   catch (MyException $e) {
      echo $e->getMessageMap();
   }

?>


           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Development
» Your own Exceptions