-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
ErrorHandlerFeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Description
Now that we have a separate component named ErrorHandler
, I have an idea.
It's quite common to do this in the userland code:
$handle = @fopen('file.txt', 'rb');
if (false === $handle) {
throw new FileNotFoundException();
}
I think it would be nice to have a DSL for better handling of such cases:
$handle = errorHandler()
->try(static function() {
return fopen('file.txt', 'rb');
})
// or ->try('fopen', 'file.txt', 'rb')
->catchWarning(static function(string $message) {
throw new FileNotFoundException();
})
// ->catchNotice()
;
Or with some reusability options:
$fopen = errorHandler('fopen')
->catchWarning(static function(string $message) {
throw new FileNotFoundException();
})
;
$fopen('file.txt', 'rb');
$fopen('another.xml', 'wb');
This mechanism could replace error handling in the Filesystem
and other components across the framework.
@yceruto , WDYT?
linaori
Metadata
Metadata
Assignees
Labels
ErrorHandlerFeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)