function hideme($auth=''){
//try something first
try{
//if not TRUE throw an exception with error message
if(empty($auth)) throw new Kohana_User_Exception('Parameter Empty','You should include a value');
//following lines won't work if an exception occur
//another method where an exception may occur
$this->checkNum($auth);
//the last line of try catch block and if you see this text. Error FREE :)
echo 'You passed a number :: '.$auth;
//catch specific kohana_user_exception because it inheritance from kohana_exception
}catch(kohana_user_exception $e){
//call a method before die:: very useful for closing </html> tags or closing DB
die($this->error_handler($e));
//not necessary in this sample code but if above exceptions fail to catch..
//at least parent exception should be called like this
}catch(kohana_exception $e){
die($e->getMessage());
}
}
//to be called before die
private function error_handler($e){
echo 'do something before die!<br />';
echo $e;
}
function checkNum($num){
if(!(int)$num > 0) throw new Kohana_User_Exception('Invalid Number','This value is not a number. Please provide a valid number.');
return TRUE;
}