Removed exception conversion stuff.

This commit is contained in:
flash 2024-07-31 19:20:55 +00:00
parent 285e2de40c
commit 13d2edb7c3
5 changed files with 5 additions and 94 deletions

View file

@ -1 +1 @@
0.2407.311911 0.2407.311920

View file

@ -7,13 +7,3 @@ namespace Index;
define('NDX_ROOT', __DIR__); define('NDX_ROOT', __DIR__);
define('NDX_DIR_SRC', NDX_ROOT . DIRECTORY_SEPARATOR . 'src'); define('NDX_DIR_SRC', NDX_ROOT . DIRECTORY_SEPARATOR . 'src');
// currently phpstan sucks and relies on error suppression, luckily it leaves a constant!
if(!defined('__PHPSTAN_RUNNING__')) {
// defining this WILL cause issues, never do it unless you HAVE to
if(!defined('NDX_LEAVE_ERRORS'))
Exceptions::convertErrors();
if(!defined('NDX_LEAVE_EXCEPTIONS'))
Exceptions::handleExceptions();
}

View file

@ -1,79 +0,0 @@
<?php
// Exceptions.php
// Created: 2021-04-30
// Updated: 2021-05-12
namespace Index;
use ErrorException;
use Throwable;
/**
* Provides handling for uncaught exceptions and errors.
*/
final class Exceptions {
/**
* Convert errors to ErrorExceptions.
*
* Automatically invoked by inclusion of index.php into your project unless the constant <code>NDX_LEAVE_ERRORS</code> is defined beforehand.
* This is not recommended as it may cause undefined behaviour in some classes.
* This will also make error suppression not work, luckily you've not been using that since PHP 5. Right? Right?!
* Besides, this makes it possible to try..catch errors.
*/
public static function convertErrors(): void {
self::restoreErrors();
set_error_handler([self::class, 'handleError'], -1);
}
/**
* Restores error handling to the default PHP state.
*/
public static function restoreErrors(): void {
restore_error_handler();
}
/**
* Handle uncaught exceptions.
*
* Automatically invoked by inclusion of index.php into your project unless the constant <code>NDX_LEAVE_EXCEPTIONS</code> is defined.
*/
public static function handleExceptions(): void {
self::restoreExceptions();
//set_exception_handler([self::class, 'handleException']);
}
/**
* Restores uncaught exception handling to the default PHP state.
*/
public static function restoreExceptions(): void {
restore_exception_handler();
}
/**
* Converts errors to ErrorExceptions.
*
* Paramater documentation is copied from the set_error_handler page on php.net
*
* @see https://www.php.net/manual/en/function.set-error-handler.php
* @param int $errno The first parameter, errno, will be passed the level of the error raised, as an integer.
* @param string $errstr The second parameter, errstr, will be passed the error message, as a string.
* @param string $errfile If the callback accepts a third parameter, errfile, it will be passed the filename that the error was raised in, as a string.
* @param int $errline If the callback accepts a fourth parameter, errline, it will be passed the line number where the error was raised, as an integer.
* @throws ErrorException An ErrorException with the provided parameters.
* @return bool if this were false the PHP error handler would continue, but returning is never reached.
*/
public static function handleError(int $errno, string $errstr, string $errfile, int $errline): bool {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
/**
* Handles uncaught exceptions.
*
* @see https://www.php.net/manual/en/function.set-exception-handler.php
* @param ?Throwable $ex Uncaught Throwable to handle. May be null to reset state(?) apparently.
*/
public static function handleException(?Throwable $ex): void {
if($ex === null)
return;
}
}

View file

@ -1,7 +1,7 @@
<?php <?php
// FileStream.php // FileStream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2022-02-27 // Updated: 2024-07-31
namespace Index\IO; namespace Index\IO;
@ -36,7 +36,7 @@ class FileStream extends GenericStream {
} }
if($stream === false) if($stream === false)
throw new IOException('An unhandled error occurred while trying to open a file. Exceptions::convertErrors() has probably not been called.'); throw new IOException('An unhandled error occurred while trying to open a file.');
parent::__construct($stream); parent::__construct($stream);

View file

@ -1,7 +1,7 @@
<?php <?php
// NetworkStream.php // NetworkStream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2022-02-27 // Updated: 2024-07-31
namespace Index\IO; namespace Index\IO;
@ -18,7 +18,7 @@ class NetworkStream extends GenericStream {
} }
if($stream === false) if($stream === false)
throw new IOException('An unhandled error occurred while trying to connect. Exceptions::convertErrors() has probably not been called.'); throw new IOException('An unhandled error occurred while trying to connect.');
parent::__construct($stream); parent::__construct($stream);
} }