I've wrote a custom exception class in PHP:
<?php
class Custom_Exception extends Exception {
public function __construct( $title, $message, $code = 0, Exception $previous = null ) {
parent::__construct( $message, $code, $previous );
echo '<html>';
echo '<head>';
echo '<title>Custom Exception: ' . $title . '</title>';
echo '</head>';
echo '<body>';
echo '<h1>Custom Exception</h1>';
echo '<hr />';
echo '<p><strong>Error: </strong>' . $title . '</p>';
echo '<p><strong>Message: </strong><em>' . $message . '</em></p>';
echo '<hr />';
echo '<p>This Exception was raised on: ' . date( 'Y-m-d' ) . ' at ' . date( 'H:i:s' ) . '.';
echo '</body>';
echo '</html>';
http_response_code( $code );
die();
}
}
Is it a good practice to end my __construct
overriden method with die()
, to prevent outputing any parent class "Exception
" messages?
As you see it outputs an HTML response into the browser. I've never dealed with custom PHP exceptions before, so I would like to know does this bother any conventions, etc?