static-php-cli/src/SPC/exception/ExceptionHandler.php

28 lines
689 B
PHP
Raw Normal View History

2023-03-15 20:40:49 +08:00
<?php
declare(strict_types=1);
namespace SPC\exception;
class ExceptionHandler
{
protected mixed $whoops = null;
2023-03-15 20:40:49 +08:00
private static ?ExceptionHandler $obj = null;
2023-03-15 20:40:49 +08:00
public static function getInstance(): ExceptionHandler
{
if (self::$obj === null) {
self::$obj = new self();
}
return self::$obj;
}
public function handle(\Throwable $e): void
{
2025-08-01 01:29:35 +08:00
logger()->error('Uncaught ' . get_class($e) . ': ' . $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')');
logger()->error($e->getTraceAsString());
logger()->critical('You can report this exception to static-php-cli GitHub repo.');
2023-03-15 20:40:49 +08:00
}
}