devorto/exception-handler

一个将标准PHP错误转换为异常的类,并支持将(未)捕获的异常记录到php-log和其他使用LoggerInterface的日志记录器。

3.0.0 2024-03-24 20:19 UTC

This package is auto-updated.

Last update: 2024-09-24 21:18:37 UTC


README

是否一直想将PHP错误转换为异常?或者捕获“未捕获的异常”,以便使用日志记录器记录它们?

无需再寻找,现在就包含这个类吧!😁

示例

<?php

// Init ExceptionHandler class:
\Devorto\ExceptionHandler::init();

// Add a logger.
\Devorto\ExceptionHandler::addLogger(new AnyLoggerImplementingLoggerInterface());

// This class removes the need of using `@` before php standard methods because we can now catch and continue with our code but still log that this happened.
try {
	mkdir('/existing-path-which-results-in-a-notice');
} catch (ErrorException $exception) {
	// Log "caught" exception.
	\Devorto\ExceptionHandler::log($exception);
}

/**
 * This will result in a HTTP 500 Error Page.
 * This will however be logged using the exception handler and provided loggers.
 */
throw new Exception('It broke!');