[ create a new paste ] login | about

Link: http://codepad.org/4MjNDWcW    [ raw code | output | fork ]

php.programmer - PHP, pasted on May 4:
<?php
// sample code to illustrate the use of exception class in oops to handle the errors 
// this is very basic function , I will update this later.
// http://royads.blogspot.com

class customException extends Exception
{
   public function errorMessage()
  { 
   $error = "Error - Line : ".$this->getLine()."\n";
   $error .= "Error - File : ".$this->getFile()."\n";
   $error .= "Error - Code : [".$this->getCode()."]\n";
   $error .= "Error - Trace : ".$this->getTraceAsString()."\n";
   $error .= "Error - Message : ".$this->getMessage()."\n";
   return $error;
  }
}

 function showMeIfInt($me)
 {
  if(is_int($me))
   echo $me."\n";
  else
   throw new customException('Me not integer');
 }

showMeIfInt(34);
try {
showMeIfInt('test');
}
catch(Exception $e)
{
  echo $e->errorMessage();
}
?>


Output:
1
2
3
4
5
6
7
34
Error - Line : 24
Error - File : /t.php
Error - Code : [0]
Error - Trace : #0 /t.php(29): showMeIfInt('test')
#1 {main}
Error - Message : Me not integer


Create a new paste based on this one


Comments: