简体   繁体   中英

PHP exception overwirte toString()

I'm having problems with my own exception class: IOExeption . I want it to have another output then the normal exception class but in spite of the code below, its output is still the same.
What am I doing wrong ?

class IOExeption extends Exception
{
    public function __toString()
    {
        $string  = '<h1 class="text-warning text-center">';
        $string .= $this->getMessage();
        $string .= '</h1>';
        return $string;
    }
}

As a matter of fact, exceptions should have no output at all .

Whatever output have to be done in the exception handler only . And only in case it is development server which the only user you are. Otherwise it have to log the error message in plain text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM