php - Exception Catch and CallHook -


i'm using callhook execute classes , methods in mvc framework. no add error-handling php exception function. i'm wondering best place execute catch command. request can (of course) lead execution of multiple classes. throughout system exceptions made. (example mentioned below).

function callhook() {     global $urlarray;     //define controllers     if (strlen(strstr($urlarray[0],'popup_'))>0)     {         $controller = substr($urlarray[0], 6);     }     else     {         $controller = $urlarray[0];      }     $querystring[] = $urlarray[1];     $urlaction = $urlarray[2];      if(!isset($controller) && empty($controller)){ $controller = 'home';}     if(!isset($urlaction) || empty($urlaction)){$action = 'view';}else{$action = $urlaction;}      $controllername = str_replace('-','', $controller);     $controller = ucwords($controller);     $model = rtrim($controller, 's');     $controller .= 'controller';     $dispatch = new $controller($model,$controllername,$action);      if ((int)method_exists($controller, $action)) {         $resultarray = call_user_func_array(array($dispatch,$action),$querystring);         return $resultarray;     } else {         exit("fatal error: 101.".$controller."-".$action);     } } 

example class:

public function checkcarexistance(){     if(!is_object($this-> carid)){throw new exception("carid missing!");}         $countcars = new modelmysql();         $countcars->connect();         $countcars->count('system_cars', "carid = '".mysql_real_escape_string($this-> carid)."'");         $this->results = $countcars ->getresult();  }    

to display exceptions idea place try/catch in call hook or in every class/method?

callhook

if ((int)method_exists($controller, $action)) {         try{             $resultarray = call_user_func_array(array($dispatch,$action),$querystring);             return $resultarray;         }         catch(exception $e){           echo 'error found message: ' .$e->getmessage() .' <br />\n";';         }      } else {         exit("fatal error: 101.".$controller."-".$action);     } 

so in way

try{     if ((int)method_exists($controller, $action)) {         throw new exception("fatal error: 101.".$controller."-".$action);     }     $resultarray = call_user_func_array(array($dispatch,$action),$querystring);     return $resultarray; } catch(exception $e){    exit( 'fatal error: ' .$e->getmessage() .' <br />\n"'); } 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -