pmmp/ErrorHandler

Add ErrorToExceptionHandler::call() to allow explicitly transforming errors into exceptions, even if the global ErrorToExceptionHandler was not set

Closed this issue · 0 comments

As per title.

Many parts of the PM core are currently forced to account for the possibility that standard library functions will return false. While we know that usually the ErrorToExceptionHandler will be set, meaning those false returns would never appear, we can't be sure that will always be the case, since other user code can overwrite the error handler, implicitly breaking this assumption.

To combat this problem, a method should be introduced that behaves like so:

ErrorToExceptionHandler::set();
try{
    return $userCallback();
}finally{
    restore_error_handler();
}

This would ensure that the baseline requirements for PM's core assumptions would be met regardless of the context it's called in.

This would also solve another long-standing problem with how to capture error information consistently (pmmp/PocketMine-MP#3405).