codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?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(); } ?>
Private
[
?
]
Run code