PHP code example of webfiori / err
1. Go to this page and download the library: Download webfiori/err library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webfiori / err example snippets
php
namespace webfiori\error;
class DefaultExceptionsHandler extends AbstractExceptionHandler {
public function __construct() {
parent::__construct();
//Set handler name. Each registered handler must have a unique name.
$this->setName('Cool Handler');
//Sets the priority of the handler. Larger means that it has higher priority.
$this->setPriority(100);
}
/**
* Handles the exception.
*/
public function handle() {
echo '<pre>';
echo 'An exception was thrown at '.$this->getClass().' line '.$this->getLine().'.<br>';
echo 'Exception message: '.$this->getMessage().'.<br>';
echo 'Stack trace:<br>';
$trace = $this->getTrace();
if (count($trace) == 0) {
echo '<Empty>';
} else {
$index = '0';
foreach ($trace as $entry) {
echo '#'.$index.' '.$entry.'<br>';
$index++;
}
}
echo '</pre>';
}
public function isActive(): bool {
//Activate or deactivate the handler based on conditions.
return true;
}
public function isShutdownHandler(): bool {
//Set the handler as shutdown handler (errors after processing)
return false;
}
}
php
Handler::registerHandler(new DefaultExceptionsHandler());