Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function logErrors($errorArray, $other_params){
- // OK, itt naplózzuk a hibákat
- // .................
- }
- class MySpecialException extends Exception
- {
- public function __construct($message, $code = 0, Exception $previous = null){
- $logParams = array('egyiktökmindegy', 'megmégvalami');
- logErrors($message);
- if(is_array($message)){
- $message = implode('<br />', $message);
- }
- parent::__construct($message, $code, $previous);
- }
- }
- class MyOtherSpecialException extends Exception
- {
- public function __construct($message, $code = 0, Exception $previous = null){
- $logParams = array('másiktökmindegy', 'megmégvalami');
- logErrors($message);
- if(is_array($message)){
- $message = implode('<br />', $message);
- }
- parent::__construct($message, $code, $previous);
- }
- }
- class MyClass {
- function blabla(){
- // .......
- $errorArray = array();
- if( $hiba_van ){
- $errorArray[] = 'ezért meg azért';
- }
- if(!empty($errorArray)){
- throw new MySpecialException($errorArray);
- }
- // ...
- }
- function masikblabla(){
- // .........
- $errorArray = array();
- if( $hiba_van ){
- $errorArray[] = 'ezért meg azért';
- }
- if(!empty($errorArray)){
- throw new MyOtherSpecialException($errorArray);
- }
- // .......................
- }
- }
- //**************************************************************************************
- // akkor most használjuk is a függvényeinket
- try{
- $myClass = new MyClass();
- $myClass->blabla();
- $myClass->masikblabla();
- // SIKER
- echo 'jé, csak eljutottunk idáig is, minden rendben volt.....';
- } catch (MySpecialException $e){
- // ....
- echo $e->getMessage();
- } catch (MyOtherSpecialException $e){
- // ....
- echo $e->getMessage();
- } catch (Exception $e){
- // ....
- echo $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement