Exception class maken

Gestart doorLuukvdo3 reacties61 weergaven

4 berichten · pagina 1 van 1

Luukvdo

Lid · Topicstarter

Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo biggrin
Ik ben bezig met mijn eigen site en ik wil graag een exception class maken ipv overal

try
{
    // code
}
catch(Exception $e)
{
    $this->error($e);
}


te doen.

Nu weet ik dat je dan zoiets moet doen

class ExceptionClass extends Exception


Maar verder zou ik niet weten wat ik moet doen.
Daar zoek ik dus hulp bij

Alvast bedankt,
Luuk
0
Luukvdo

Lid · Topicstarter

Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb nu de volgende code:

[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/class"]class[/URL] ExceptionClass extends Exception
    [COLOR= #007700]{[/COLOR]        
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$message[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR] Exception [COLOR= #0000BB]$previous[/COLOR] [COLOR= #007700]=[/COLOR] null[COLOR= #007700])
        {[/COLOR]
            parent[COLOR= #007700]::[/COLOR]__construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$message[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$code[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$previous[/COLOR][COLOR= #007700]);
        }[/COLOR]
        
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __toString[COLOR= #007700]()
        {[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_object"]is_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]message[COLOR= #007700]))[/COLOR]
                [COLOR= #0000BB]$v[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/sprintf"]sprintf[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]<strong>Line:</strong> <em>%s</em><br /><strong>File:</strong><br /> em>%s</em><br /><strong>Request-URI</strong><br /><em>%s</em><br /><strong>Error:</strong><br /> <em>%s</em>[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]getLine[COLOR= #007700](),[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]getFile[COLOR= #007700](),[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_URI[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]getMessage[COLOR= #007700]());[/COLOR]
            [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_string"]is_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]message[COLOR= #007700]))[/COLOR]
                [COLOR= #0000BB]$v[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]message[COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/sprintf"]sprintf[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]<div style="width:50%%;margin: 0px auto; text-align:center;padding:15px;border: 1px solid #962133; border-bottom: 2px solid #962133;background-color: #f75353;">%s</div><br /><br />[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$v[/COLOR][COLOR= #007700]);
        }
    }[/COLOR]
?>


Maar hij geeft aan Uncaught Exception confusedWat doe ik fout? emo
0
Berichten
5.209
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Op verzoek van topic starter gesloten.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren