PHP/Development/Your own Exceptions — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:37, 26 мая 2010
Define and use your own exception class
<source lang="html4strict">
<?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(); }
?>
</source>